Skip to content

Commit

Permalink
fix(webserver): disable scheduler jobs in current upcoming release (T…
Browse files Browse the repository at this point in the history
…abbyML#1274)

* fix(webserver): disable scheduler jobs in current upcoming release

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
wsxiaoys and autofix-ci[bot] authored Jan 22, 2024
1 parent 8e36bee commit f0c2de9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
41 changes: 25 additions & 16 deletions ee/tabby-webserver/src/service/cron/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,38 @@ async fn new_job_scheduler(jobs: Vec<Job>) -> anyhow::Result<JobScheduler> {
Ok(scheduler)
}

pub fn run_cron(db_conn: &DbConn) {
pub fn run_cron(db_conn: &DbConn, turn_on_scheduler_jobs: bool) {
let db_conn = db_conn.clone();
tokio::spawn(async move {
let mut jobs = vec![];

let Ok(job1) = db::refresh_token_job(db_conn.clone()).await else {
error!("failed to create db job");
return;
};
// run every 5 minutes
let Ok(job2) =
job_utils::run_job(db_conn.clone(), "sync".to_owned(), "0 1/5 * * * * *").await
else {
error!("failed to create sync job");
return;
};
// run every 5 hours
let Ok(job3) =
job_utils::run_job(db_conn.clone(), "index".to_owned(), "0 0 1/5 * * * *").await
else {
error!("failed to create index job");
return;
};
jobs.push(job1);

if turn_on_scheduler_jobs {
// run every 5 minutes
let Ok(job2) =
job_utils::run_job(db_conn.clone(), "sync".to_owned(), "0 1/5 * * * * *").await
else {
error!("failed to create sync job");
return;
};
jobs.push(job2);

// run every 5 hours
let Ok(job3) =
job_utils::run_job(db_conn.clone(), "index".to_owned(), "0 0 1/5 * * * *").await
else {
error!("failed to create index job");
return;
};
jobs.push(job3);
}

let Ok(mut scheduler) = new_job_scheduler(vec![job1, job2, job3]).await else {
let Ok(mut scheduler) = new_job_scheduler(jobs).await else {
error!("failed to start job scheduler");
return;
};
Expand Down
2 changes: 1 addition & 1 deletion ee/tabby-webserver/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct ServerContext {
impl ServerContext {
pub async fn new(logger: Arc<dyn RawEventLogger>, code: Arc<dyn CodeSearch>) -> Self {
let db_conn = DbConn::new().await.unwrap();
run_cron(&db_conn);
run_cron(&db_conn, false);
Self {
client: Client::default(),
completion: worker::WorkerGroup::default(),
Expand Down

0 comments on commit f0c2de9

Please sign in to comment.