Skip to content

Commit

Permalink
chore(webserver): improve error log for each cron job to make it easi…
Browse files Browse the repository at this point in the history
…er to identify the stack trace
  • Loading branch information
wsxiaoys committed Apr 26, 2024
1 parent cb9a8a7 commit 776d0f7
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions ee/tabby-webserver/src/cron/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const EVERY_TWO_HOURS: &str = "0 0 1/2 * * * *";
const EVERY_TEN_MINUTES: &str = "0 1/10 * * * *";

async fn service_job<F, S>(
name: &str,
frequency: &'static str,
service: Arc<S>,
job: fn(Arc<S>) -> F,
Expand All @@ -25,12 +26,14 @@ where
F: Future<Output = Result<()>> + 'static + Send,
S: Send + Sync + 'static + ?Sized,
{
let name = name.to_owned();
let job = Job::new_async(frequency, move |_, _| {
let name = name.clone();
let auth = service.clone();
Box::pin(async move {
let res = job(auth.clone()).await;
if let Err(e) = res {
error!("failed to run cleanup job: {}", e);
error!("Failed to run `{name}` job: {}", e);
}
})
})?;
Expand All @@ -39,23 +42,30 @@ where
}

pub async fn refresh_token_job(auth: Arc<dyn AuthenticationService>) -> Result<Job> {
service_job(EVERY_TWO_HOURS, auth, |auth| async move {
Ok(auth.delete_expired_token().await?)
})
service_job(
"cleanup staled refresh token",
EVERY_TWO_HOURS,
auth,
|auth| async move { Ok(auth.delete_expired_token().await?) },
)
.await
}

pub async fn password_reset_job(auth: Arc<dyn AuthenticationService>) -> Result<Job> {
service_job(EVERY_TWO_HOURS, auth, |auth| async move {
Ok(auth.delete_expired_password_resets().await?)
})
service_job(
"cleanup staled password reset",
EVERY_TWO_HOURS,
auth,
|auth| async move { Ok(auth.delete_expired_password_resets().await?) },
)
.await
}

pub async fn update_integrated_github_repositories_job(
github_repository_provider: Arc<dyn GithubRepositoryProviderService>,
) -> Result<Job> {
service_job(
"sync github repositories",
EVERY_TEN_MINUTES,
github_repository_provider,
|github_repository_provider| async move {
Expand All @@ -70,6 +80,7 @@ pub async fn update_integrated_gitlab_repositories_job(
gitlab_repository_provider: Arc<dyn GitlabRepositoryProviderService>,
) -> Result<Job> {
service_job(
"sync gitlab repositories",
EVERY_TEN_MINUTES,
gitlab_repository_provider,
|gitlab_repository_provider| async move {
Expand Down

0 comments on commit 776d0f7

Please sign in to comment.