(toggl-portal): Scheduling pain

This commit is contained in:
Joshua Coles 2023-11-05 15:56:45 +00:00
parent 1d726b76c4
commit 6971e4a874
4 changed files with 12 additions and 4 deletions

View File

@ -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"

View File

@ -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::<Vec<ReportEntry>>()
.await?;

View File

@ -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;

View File

@ -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<usize> {
pub async fn perform_poll(
client: &TogglClient,
db: &DatabaseConnection,
) -> beachhead::Result<usize> {
let report = client
.full_report(&TogglQuery {
start_date: Some(