Skip to content

Commit

Permalink
refactor: app run code and update creat_or_update
Browse files Browse the repository at this point in the history
  • Loading branch information
fan-tastic-z committed Jun 12, 2024
1 parent d6877b7 commit c306b23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Job> {
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,
Expand All @@ -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?;
Expand Down
2 changes: 2 additions & 0 deletions src/models/vuln_informations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c306b23

Please sign in to comment.