cleanup: replace id from do_sync_job with info from job

we already have it inside the job itself

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2020-08-13 14:30:18 +02:00 committed by Dietmar Maurer
parent 77bd2a469c
commit 713b66b6ed
4 changed files with 15 additions and 8 deletions

View File

@ -90,7 +90,7 @@ fn run_sync_job(
let mut job = Job::new("syncjob", &id)?; let mut job = Job::new("syncjob", &id)?;
job.load()?; job.load()?;
let upid_str = do_sync_job(&id, sync_job, &userid, None, job)?; let upid_str = do_sync_job(job, sync_job, &userid, None)?;
Ok(upid_str) Ok(upid_str)
} }

View File

@ -66,19 +66,18 @@ pub async fn get_pull_parameters(
} }
pub fn do_sync_job( pub fn do_sync_job(
id: &str, mut job: Job,
sync_job: SyncJobConfig, sync_job: SyncJobConfig,
userid: &Userid, userid: &Userid,
schedule: Option<String>, schedule: Option<String>,
mut job: Job,
) -> Result<String, Error> { ) -> Result<String, Error> {
let job_id = id.to_string(); let job_id = job.jobname().to_string();
let worker_type = "syncjob"; let worker_type = job.jobtype().to_string();
let upid_str = WorkerTask::spawn( let upid_str = WorkerTask::spawn(
worker_type, &worker_type,
Some(id.to_string()), Some(job.jobname().to_string()),
userid.clone(), userid.clone(),
false, false,
move |worker| async move { move |worker| async move {

View File

@ -548,7 +548,7 @@ async fn schedule_datastore_sync_jobs() {
let userid = Userid::backup_userid().clone(); let userid = Userid::backup_userid().clone();
if let Err(err) = do_sync_job(&job_id, job_config, &userid, Some(event_str), job) { if let Err(err) = do_sync_job(job, job_config, &userid, Some(event_str)) {
eprintln!("unable to start datastore sync job {} - {}", &job_id, err); eprintln!("unable to start datastore sync job {} - {}", &job_id, err);
} }
} }

View File

@ -232,6 +232,14 @@ impl Job {
self.write_state() self.write_state()
} }
pub fn jobtype(&self) -> &str {
&self.jobtype
}
pub fn jobname(&self) -> &str {
&self.jobname
}
fn write_state(&mut self) -> Result<(), Error> { fn write_state(&mut self) -> Result<(), Error> {
let serialized = serde_json::to_string(&self.state)?; let serialized = serde_json::to_string(&self.state)?;
let path = get_path(&self.jobtype, &self.jobname); let path = get_path(&self.jobtype, &self.jobname);