-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(job): change daily and hourly cron into standalone job
Signed-off-by: Wei Zhang <[email protected]>
- Loading branch information
Showing
4 changed files
with
141 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::service::background_job::LicenseCheckJob; | ||
use chrono::Utc; | ||
use serde::{Deserialize, Serialize}; | ||
use tabby_schema::{license::LicenseService, notification::NotificationService}; | ||
|
||
use super::helper::Job; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct DailyJob; | ||
|
||
impl Job for DailyJob { | ||
const NAME: &'static str = "daily"; | ||
} | ||
|
||
impl DailyJob { | ||
pub async fn run( | ||
&self, | ||
license_service: Arc<dyn LicenseService>, | ||
notification_service: Arc<dyn NotificationService>, | ||
) -> tabby_schema::Result<()> { | ||
let now = Utc::now(); | ||
|
||
if let Err(err) = | ||
LicenseCheckJob::cron(now, license_service.clone(), notification_service.clone()).await | ||
{ | ||
logkit::warn!("License check job failed: {err:?}"); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use std::sync::Arc; | ||
|
||
use crate::service::background_job::{ | ||
db::DbMaintainanceJob, IndexGarbageCollection, SchedulerGitJob, SchedulerGithubGitlabJob, | ||
SyncIntegrationJob, | ||
}; | ||
use chrono::Utc; | ||
use serde::{Deserialize, Serialize}; | ||
use tabby_db::DbConn; | ||
use tabby_schema::{ | ||
context::ContextService, | ||
integration::IntegrationService, | ||
job::JobService, | ||
repository::{GitRepositoryService, RepositoryService, ThirdPartyRepositoryService}, | ||
}; | ||
|
||
use super::helper::Job; | ||
|
||
#[derive(Debug, Serialize, Deserialize, Clone)] | ||
pub struct HourlyJob; | ||
|
||
impl Job for HourlyJob { | ||
const NAME: &'static str = "hourly"; | ||
} | ||
|
||
impl HourlyJob { | ||
pub async fn run( | ||
&self, | ||
db: DbConn, | ||
context_service: Arc<dyn ContextService>, | ||
git_repository_service: Arc<dyn GitRepositoryService>, | ||
job_service: Arc<dyn JobService>, | ||
integration_service: Arc<dyn IntegrationService>, | ||
third_party_repository_service: Arc<dyn ThirdPartyRepositoryService>, | ||
repository_service: Arc<dyn RepositoryService>, | ||
) -> tabby_schema::Result<()> { | ||
let now = Utc::now(); | ||
|
||
if let Err(err) = DbMaintainanceJob::cron(now, context_service.clone(), db.clone()).await { | ||
logkit::warn!("Database maintainance failed: {:?}", err); | ||
} | ||
|
||
if let Err(err) = | ||
SchedulerGitJob::cron(now, git_repository_service.clone(), job_service.clone()).await | ||
{ | ||
logkit::warn!("Scheduler job failed: {:?}", err); | ||
} | ||
|
||
if let Err(err) = | ||
SyncIntegrationJob::cron(now, integration_service.clone(), job_service.clone()).await | ||
{ | ||
logkit::warn!("Sync integration job failed: {:?}", err); | ||
} | ||
|
||
if let Err(err) = SchedulerGithubGitlabJob::cron( | ||
now, | ||
third_party_repository_service.clone(), | ||
job_service.clone(), | ||
) | ||
.await | ||
{ | ||
logkit::warn!("Index issues job failed: {err:?}"); | ||
} | ||
|
||
if let Err(err) = IndexGarbageCollection | ||
.run(repository_service.clone(), context_service.clone()) | ||
.await | ||
{ | ||
logkit::warn!("Index garbage collection job failed: {err:?}"); | ||
} | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters