Allow zero time_entries
This commit is contained in:
+7
-3
@@ -53,13 +53,14 @@ impl Worker {
|
||||
}
|
||||
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_one(&mut self.db)
|
||||
.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.last_updated_at
|
||||
let fetch_since = result
|
||||
.and_then(|record| record.last_updated_at)
|
||||
.unwrap_or_else(|| Utc::now() - default_look_back);
|
||||
|
||||
let time_entries = self.toggl_api
|
||||
@@ -291,6 +292,9 @@ async fn main() {
|
||||
dotenv::dotenv()
|
||||
.expect("Failed to load .env file");
|
||||
|
||||
// Init tracing
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let api = TogglApi::new(
|
||||
sensitive::API_TOKEN,
|
||||
sensitive::WORKSPACE_ID,
|
||||
@@ -304,7 +308,7 @@ async fn main() {
|
||||
toggl_api: api,
|
||||
};
|
||||
|
||||
worker.update(TimeDelta::days(7))
|
||||
worker.update(TimeDelta::days(90))
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user