From: Dietmar Maurer <dietmar@proxmox.com>
To: Proxmox Backup Server development discussion
<pbs-devel@lists.proxmox.com>,
Dominik Csapak <d.csapak@proxmox.com>
Subject: Re: [pbs-devel] [PATCH proxmox-backup 4/8] api2/pull: add do_syn_job helper
Date: Mon, 3 Aug 2020 09:42:32 +0200 (CEST) [thread overview]
Message-ID: <898737988.49.1596440553389@webmail.proxmox.com> (raw)
In-Reply-To: <20200731124330.30576-5-d.csapak@proxmox.com>
Please can we first have a patch to split out do_syn_job from src/api2/admin/sync.rs?
> On 07/31/2020 2:43 PM Dominik Csapak <d.csapak@proxmox.com> wrote:
>
>
> this helper is inspired by our code in proxmox-backup-proxy
> with an added JobState writing
>
> Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
> ---
> src/api2/pull.rs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 70 insertions(+)
>
> diff --git a/src/api2/pull.rs b/src/api2/pull.rs
> index cf7de524..e788d20f 100644
> --- a/src/api2/pull.rs
> +++ b/src/api2/pull.rs
> @@ -12,6 +12,8 @@ use crate::client::{HttpClient, HttpClientOptions, BackupRepository, pull::pull_
> use crate::api2::types::*;
> use crate::config::{
> remote,
> + sync::SyncJobConfig,
> + jobstate::JobState,
> acl::{PRIV_DATASTORE_BACKUP, PRIV_DATASTORE_PRUNE, PRIV_REMOTE_READ},
> cached_user_info::CachedUserInfo,
> };
> @@ -62,6 +64,74 @@ pub async fn get_pull_parameters(
> Ok((client, src_repo, tgt_store))
> }
>
> +pub fn do_sync_job(
> + id: &str,
> + sync_job: SyncJobConfig,
> + userid: &str,
> + schedule: Option<String>,
> +) -> Result<String, Error> {
> +
> + let job_id = id.to_string();
> + let job_id2 = id.to_string();
> + let worker_type = "syncjob";
> + let upid_str = WorkerTask::spawn(
> + worker_type,
> + Some(id.to_string()),
> + &userid.clone(),
> + false,
> + move |worker| async move {
> +
> + let mut state = JobState::new(&worker.upid().to_string());
> + match state.write_state(worker_type, &job_id2, None) {
> + Ok(_) => {},
> + Err(err) => {
> + eprintln!("could not write job state on start: {}", err);
> + }
> + }
> +
> + let worker2 = worker.clone();
> +
> + let res = async move {
> +
> + let delete = sync_job.remove_vanished.unwrap_or(true);
> + let (client, src_repo, tgt_store) = get_pull_parameters(&sync_job.store, &sync_job.remote, &sync_job.remote_store).await?;
> +
> + worker.log(format!("Starting datastore sync job '{}'", job_id));
> + if let Some(event_str) = schedule {
> + worker.log(format!("task triggered by schedule '{}'", event_str));
> + }
> + worker.log(format!("Sync datastore '{}' from '{}/{}'",
> + sync_job.store, sync_job.remote, sync_job.remote_store));
> +
> + crate::client::pull::pull_store(&worker, &client, &src_repo, tgt_store.clone(), delete, String::from("backup@pam")).await?;
> +
> + worker.log(format!("sync job '{}' end", &job_id));
> +
> + Ok(())
> + }.await;
> +
> + let status = worker2.get_log_text(&res);
> +
> + match state.finish(&status) {
> + Ok(_) => {},
> + Err(err) => {
> + eprintln!("could not finish job state: {}", err);
> + }
> + }
> +
> + match state.write_state(&worker_type, &job_id2, None) {
> + Ok(_) => {},
> + Err(err) => {
> + eprintln!("could not write job state on finish: {}", err);
> + }
> + }
> +
> + res
> + })?;
> +
> + Ok(upid_str)
> +}
> +
> #[api(
> input: {
> properties: {
> --
> 2.20.1
>
>
>
> _______________________________________________
> pbs-devel mailing list
> pbs-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2020-08-03 7:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-31 12:43 [pbs-devel] [PATCH proxmox-backup 0/8] improve syncjob handling Dominik Csapak
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 1/8] worker_task: refactor log text generator Dominik Csapak
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 2/8] worker_task: add getter for upid Dominik Csapak
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 3/8] config: add JobState helper Dominik Csapak
2020-08-03 7:35 ` Dietmar Maurer
2020-08-03 7:38 ` Dietmar Maurer
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 4/8] api2/pull: add do_syn_job helper Dominik Csapak
2020-08-03 7:42 ` Dietmar Maurer [this message]
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 5/8] syncjob: use do_sync_job for manual and scheduled sync jobs Dominik Csapak
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 6/8] syncjob: use JobState for determining when to run next scheduled sync Dominik Csapak
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 7/8] api2/admin/sync: use JobState for faster access to state info Dominik Csapak
2020-07-31 12:43 ` [pbs-devel] [PATCH proxmox-backup 8/8] ui: syncjob: use the Task text directly Dominik Csapak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=898737988.49.1596440553389@webmail.proxmox.com \
--to=dietmar@proxmox.com \
--cc=d.csapak@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox