From 6971e4a87436171a7a473f2a981c28475266be32 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sun, 5 Nov 2023 15:56:45 +0000 Subject: [PATCH] (toggl-portal): Scheduling pain --- Cargo.toml | 1 + src/client.rs | 8 ++++++-- src/main.rs | 2 +- src/poll.rs | 5 ++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 56fe81e..8563620 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,3 +30,4 @@ sea-orm = { version = "0.12", features = [ migration = { path = "./migration" } chrono = { version = "0.4.31", features = ["serde"] } futures = "0.3.29" +#tokio-cron-scheduler = "0.9.4" diff --git a/src/client.rs b/src/client.rs index 281c689..83f4d8e 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,6 +2,7 @@ use reqwest::Client; use serde_json::Value; use std::collections::HashMap; use std::time::Duration; +use axum::http::StatusCode; use hyper::HeaderMap; use tracing::instrument; use tracing::log::debug; @@ -111,13 +112,16 @@ impl TogglClient { tokio::time::sleep(Duration::from_millis(1000)).await; } - let data = self + // TODO: Implement rate limiting + let response = self .client .post(&url) .headers(self.headers.clone()) .json(&Self::create_filters(&filters, last_row_number_n)) .send() - .await? + .await?; + + let data = response .json::>() .await?; diff --git a/src/main.rs b/src/main.rs index a380a35..b7ab1a9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use crate::client::TogglClient; -use crate::entity::time_entry::{self, ActiveModel, Entity as TimeEntry}; +use crate::entity::time_entry::{self, Entity as TimeEntry}; use crate::types::{Current, ReportEntry, TogglQuery}; use anyhow::anyhow; use axum::http::StatusCode; diff --git a/src/poll.rs b/src/poll.rs index ca6d184..cc11c44 100644 --- a/src/poll.rs +++ b/src/poll.rs @@ -28,7 +28,10 @@ pub async fn poll_job(client: TogglClient, db: DatabaseConnection) { } #[instrument(skip(client, db))] -pub async fn perform_poll(client: &TogglClient, db: &DatabaseConnection) -> beachhead::Result { +pub async fn perform_poll( + client: &TogglClient, + db: &DatabaseConnection, +) -> beachhead::Result { let report = client .full_report(&TogglQuery { start_date: Some(