Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(webserver): improve error log for each cron job to make it easi… #1982

Merged
merged 3 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! db maintenance jobs

mod github;
mod gitlab;

use std::{sync::Arc, time::Duration};

use anyhow::Result;
use futures::Future;
use tokio_cron_scheduler::Job;
use tracing::{debug, error};

use super::{github, gitlab};
use crate::schema::{
auth::AuthenticationService, github_repository_provider::GithubRepositoryProviderService,
gitlab_repository_provider::GitlabRepositoryProviderService, job::JobService,
Expand All @@ -17,6 +19,7 @@
const EVERY_TEN_MINUTES: &str = "0 1/10 * * * *";

async fn service_job<F, S>(
name: &str,

Check warning on line 22 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L22

Added line #L22 was not covered by tests
frequency: &'static str,
service: Arc<S>,
job: fn(Arc<S>) -> F,
Expand All @@ -25,12 +28,14 @@
F: Future<Output = Result<()>> + 'static + Send,
S: Send + Sync + 'static + ?Sized,
{
let name = name.to_owned();

Check warning on line 31 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L31

Added line #L31 was not covered by tests
let job = Job::new_async(frequency, move |_, _| {
let name = name.clone();

Check warning on line 33 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L33

Added line #L33 was not covered by tests
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);

Check warning on line 38 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L38

Added line #L38 was not covered by tests
}
})
})?;
Expand All @@ -39,23 +44,30 @@
}

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?) },
)

Check warning on line 52 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L47-L52

Added lines #L47 - L52 were not covered by tests
.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?) },
)

Check warning on line 62 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L57-L62

Added lines #L57 - L62 were not covered by tests
.await
}

pub async fn update_integrated_github_repositories_job(
github_repository_provider: Arc<dyn GithubRepositoryProviderService>,
) -> Result<Job> {
service_job(
"sync github repositories",

Check warning on line 70 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L70

Added line #L70 was not covered by tests
EVERY_TEN_MINUTES,
github_repository_provider,
|github_repository_provider| async move {
Expand All @@ -70,6 +82,7 @@
gitlab_repository_provider: Arc<dyn GitlabRepositoryProviderService>,
) -> Result<Job> {
service_job(
"sync gitlab repositories",

Check warning on line 85 in ee/tabby-webserver/src/cron/db/mod.rs

View check run for this annotation

Codecov / codecov/patch

ee/tabby-webserver/src/cron/db/mod.rs#L85

Added line #L85 was not covered by tests
EVERY_TEN_MINUTES,
gitlab_repository_provider,
|gitlab_repository_provider| async move {
Expand Down
2 changes: 0 additions & 2 deletions ee/tabby-webserver/src/cron/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
mod db;
mod github;
mod gitlab;
mod scheduler;

use std::sync::Arc;
Expand Down
Loading