diff --git a/src/app.rs b/src/app.rs index 35699ab..c4ca52d 100644 --- a/src/app.rs +++ b/src/app.rs @@ -46,18 +46,9 @@ impl WatchVulnApp { WatchVulnApp { app_context, grabs } } - pub async fn run(&self) -> Result<()> { - let self_arc = Arc::new(self.clone()); - - // init data - self_arc.crawling_task(true).await; - let local_count = vuln_informations::Model::query_count(&self.app_context.db).await?; - info!("init finished, local database has {} vulns", local_count); - self.push_init_msg(local_count).await?; - - let sched = JobScheduler::new().await?; + fn crawling_job(&self) -> Result { let schedule = self.app_context.config.task.cron_config.as_str(); - + let self_arc = Arc::new(self.clone()); let job = Job::new_async_tz( schedule, chrono_tz::Asia::Shanghai, @@ -77,6 +68,20 @@ impl WatchVulnApp { }) }, )?; + Ok(job) + } + + pub async fn run(&self) -> Result<()> { + let self_arc = Arc::new(self.clone()); + + // init data + self_arc.crawling_task(true).await; + let local_count = vuln_informations::Model::query_count(&self.app_context.db).await?; + info!("init finished, local database has {} vulns", local_count); + self.push_init_msg(local_count).await?; + + let sched = JobScheduler::new().await?; + let job = self.crawling_job()?; sched.add(job).await?; sched.start().await?; diff --git a/src/models/vuln_informations.rs b/src/models/vuln_informations.rs index 7945820..8566d36 100644 --- a/src/models/vuln_informations.rs +++ b/src/models/vuln_informations.rs @@ -89,6 +89,8 @@ impl super::_entities::vuln_informations::Model { vuln_model.from = ActiveValue::set(vuln.from); vuln_model.reasons = ActiveValue::set(Some(vuln.reasons)); vuln_model.is_valuable = ActiveValue::set(vuln.is_valuable); + // if tags or severtiy update should set pushed false, repush + vuln_model.pushed = ActiveValue::set(false); let m = vuln_model.update(&txn).await?; txn.commit().await?; return Ok(m);