Make description field optional and allow for a fixed lookback
This commit is contained in:
+13
-4
@@ -1,4 +1,4 @@
|
||||
use chrono::{TimeDelta, Utc};
|
||||
use chrono::{DateTime, TimeDelta, Utc};
|
||||
use sqlx::{Connection, PgConnection};
|
||||
use toggl::TogglApi;
|
||||
|
||||
@@ -51,18 +51,27 @@ impl Worker {
|
||||
tag_ids: tag_ids.iter().map(|row| row.id as u64).collect(),
|
||||
})
|
||||
}
|
||||
|
||||
async fn fetch_changed_since(&mut self, look_back: TimeDelta) -> Result<(), AppError> {
|
||||
self.update_time_entries(Utc::now() - look_back).await
|
||||
}
|
||||
|
||||
async fn update(&mut self, default_look_back: TimeDelta) -> Result<(), AppError> {
|
||||
let result = sqlx::query!("select max(updated_at) as last_updated_at from time_entries")
|
||||
.fetch_optional(&mut self.db)
|
||||
.await
|
||||
.expect("Could not fetch max updated_at from time_entries");
|
||||
|
||||
let existing_ids = self.get_ids().await?;
|
||||
|
||||
let fetch_since = result
|
||||
.and_then(|record| record.last_updated_at)
|
||||
.unwrap_or_else(|| Utc::now() - default_look_back);
|
||||
|
||||
self.update_time_entries(fetch_since).await
|
||||
}
|
||||
|
||||
async fn update_time_entries(&mut self, fetch_since: DateTime<Utc>) -> Result<(), AppError> {
|
||||
let existing_ids = self.get_ids().await?;
|
||||
|
||||
let time_entries = self.toggl_api
|
||||
.get_time_entries_for_user_modified_since(fetch_since).await?;
|
||||
|
||||
@@ -308,7 +317,7 @@ async fn main() {
|
||||
toggl_api: api,
|
||||
};
|
||||
|
||||
worker.update(TimeDelta::days(90))
|
||||
worker.fetch_changed_since(TimeDelta::days(90))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user