Skip to content

Commit

Permalink
[autofix.ci] apply automated fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
autofix-ci[bot] authored Apr 28, 2024
1 parent d877573 commit 0e082ca
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
56 changes: 36 additions & 20 deletions ee/tabby-webserver/src/cron/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod gitlab;

use std::sync::Arc;

use rand::Rng;


use super::{controller::JobController, every_ten_minutes, every_two_hours};
use crate::schema::{
Expand All @@ -21,33 +21,49 @@ pub async fn register_jobs(
) {
let cloned_auth = auth.clone();
controller
.register("remove_staled_refresh_token", &every_two_hours(), move || {
let auth = cloned_auth.clone();
Box::pin(async move { Ok(auth.delete_expired_token().await?) })
})
.register(
"remove_staled_refresh_token",
&every_two_hours(),
move || {
let auth = cloned_auth.clone();
Box::pin(async move { Ok(auth.delete_expired_token().await?) })
},
)
.await;

let cloned_auth = auth.clone();
controller
.register("remove_staled_password_reset", &every_two_hours(), move || {
let auth = cloned_auth.clone();
Box::pin(async move { Ok(auth.delete_expired_password_resets().await?) })
})
.register(
"remove_staled_password_reset",
&every_two_hours(),
move || {
let auth = cloned_auth.clone();
Box::pin(async move { Ok(auth.delete_expired_password_resets().await?) })
},
)
.await;

controller
.register_public("github_repositories", &every_ten_minutes(), move |context| {
let context = context.clone();
let github = github.clone();
Box::pin(async move { github::refresh_all_repositories(context, github).await })
})
.register_public(
"github_repositories",
&every_ten_minutes(),
move |context| {
let context = context.clone();
let github = github.clone();
Box::pin(async move { github::refresh_all_repositories(context, github).await })
},
)
.await;

controller
.register_public("gitlab_repositories", &every_ten_minutes(), move |context| {
let gitlab = gitlab.clone();
let context = context.clone();
Box::pin(async move { gitlab::refresh_all_repositories(context, gitlab).await })
})
.register_public(
"gitlab_repositories",
&every_ten_minutes(),
move |context| {
let gitlab = gitlab.clone();
let context = context.clone();
Box::pin(async move { gitlab::refresh_all_repositories(context, gitlab).await })
},
)
.await;
}
}
8 changes: 6 additions & 2 deletions ee/tabby-webserver/src/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,14 @@ pub async fn run_cron(

fn every_two_hours() -> String {
let mut rng = rand::thread_rng();
format!("{} {} */2 * * *", rng.gen_range(0..59), rng.gen_range(0..59))
format!(
"{} {} */2 * * *",
rng.gen_range(0..59),
rng.gen_range(0..59)
)
}

fn every_ten_minutes() -> String {
let mut rng = rand::thread_rng();
format!("{} */10 * * * *", rng.gen_range(0..59))
}
}

0 comments on commit 0e082ca

Please sign in to comment.