api: make some workers log on CLI

some workers did not log when called via cli

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-09-21 12:11:16 +02:00 committed by Thomas Lamprecht
parent f54634a890
commit bfa942c0cf
8 changed files with 25 additions and 14 deletions

View File

@ -952,11 +952,13 @@ pub fn prune_datastore(
let datastore = DataStore::lookup_datastore(&store)?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
let upid_str = WorkerTask::new_thread(
"prune",
Some(store.clone()),
auth_id.clone(),
false,
to_stdout,
move |worker| crate::server::prune_datastore(
worker.clone(),
auth_id,

View File

@ -3,7 +3,7 @@
use anyhow::{bail, format_err, Error};
use serde_json::Value;
use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment};
use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment, RpcEnvironmentType};
use proxmox::api::router::SubdirMap;
use proxmox::{list_subdirs_api_method, sortable};
@ -120,7 +120,9 @@ pub fn run_sync_job(
let job = Job::new("syncjob", &id)?;
let upid_str = do_sync_job(job, sync_job, &auth_id, None)?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
let upid_str = do_sync_job(job, sync_job, &auth_id, None, to_stdout)?;
Ok(upid_str)
}

View File

@ -5,7 +5,7 @@ use serde_json::Value;
use proxmox::api::router::SubdirMap;
use proxmox::{list_subdirs_api_method, sortable};
use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment};
use proxmox::api::{api, ApiMethod, Permission, Router, RpcEnvironment, RpcEnvironmentType};
use pbs_api_types::{
VerificationJobConfig, VerificationJobStatus, JOB_ID_SCHEMA, Authid,
@ -117,8 +117,9 @@ pub fn run_verification_job(
user_info.check_privs(&auth_id, &["datastore", &verification_job.store], PRIV_DATASTORE_VERIFY, true)?;
let job = Job::new("verificationjob", &id)?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
let upid_str = do_verification_job(job, verification_job, &auth_id, None)?;
let upid_str = do_verification_job(job, verification_job, &auth_id, None, to_stdout)?;
Ok(upid_str)
}

View File

@ -4,7 +4,7 @@ use anyhow::{bail, Error};
use serde_json::Value;
use ::serde::{Deserialize, Serialize};
use proxmox::api::{api, Router, RpcEnvironment, Permission};
use proxmox::api::{api, Router, RpcEnvironment, RpcEnvironmentType, Permission};
use proxmox::api::section_config::SectionConfigData;
use proxmox::api::schema::{ApiType, parse_property_string};
@ -114,12 +114,13 @@ pub fn create_datastore(
}
let auth_id: Authid = rpcenv.get_auth_id().unwrap().parse()?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
WorkerTask::new_thread(
"create-datastore",
Some(config.name.to_string()),
auth_id,
false,
to_stdout,
move |worker| do_create_datastore(lock, section_config, config, Some(&worker)),
)
}

View File

@ -66,6 +66,7 @@ pub fn do_sync_job(
sync_job: SyncJobConfig,
auth_id: &Authid,
schedule: Option<String>,
to_stdout: bool,
) -> Result<String, Error> {
let job_id = format!("{}:{}:{}:{}",
@ -81,7 +82,7 @@ pub fn do_sync_job(
&worker_type,
Some(job_id.clone()),
auth_id.clone(),
false,
to_stdout,
move |worker| async move {
job.start(&worker.upid().to_string())?;

View File

@ -164,6 +164,7 @@ pub fn do_tape_backup_job(
setup: TapeBackupJobSetup,
auth_id: &Authid,
schedule: Option<String>,
to_stdout: bool,
) -> Result<String, Error> {
let job_id = format!("{}:{}:{}:{}",
@ -195,7 +196,7 @@ pub fn do_tape_backup_job(
&worker_type,
Some(job_id.clone()),
auth_id.clone(),
false,
to_stdout,
move |worker| {
job.start(&worker.upid().to_string())?;
let mut drive_lock = drive_lock;
@ -307,7 +308,9 @@ pub fn run_tape_backup_job(
let job = Job::new("tape-backup-job", &id)?;
let upid_str = do_tape_backup_job(job, backup_job.setup, &auth_id, None)?;
let to_stdout = rpcenv.env_type() == RpcEnvironmentType::CLI;
let upid_str = do_tape_backup_job(job, backup_job.setup, &auth_id, None, to_stdout)?;
Ok(upid_str)
}

View File

@ -638,7 +638,7 @@ async fn schedule_datastore_sync_jobs() {
};
let auth_id = Authid::root_auth_id().clone();
if let Err(err) = do_sync_job(job, job_config, &auth_id, Some(event_str)) {
if let Err(err) = do_sync_job(job, job_config, &auth_id, Some(event_str), false) {
eprintln!("unable to start datastore sync job {} - {}", &job_id, err);
}
};
@ -674,7 +674,7 @@ async fn schedule_datastore_verify_jobs() {
Ok(job) => job,
Err(_) => continue, // could not get lock
};
if let Err(err) = do_verification_job(job, job_config, &auth_id, Some(event_str)) {
if let Err(err) = do_verification_job(job, job_config, &auth_id, Some(event_str), false) {
eprintln!("unable to start datastore verification job {} - {}", &job_id, err);
}
};
@ -710,7 +710,7 @@ async fn schedule_tape_backup_jobs() {
Ok(job) => job,
Err(_) => continue, // could not get lock
};
if let Err(err) = do_tape_backup_job(job, job_config.setup, &auth_id, Some(event_str)) {
if let Err(err) = do_tape_backup_job(job, job_config.setup, &auth_id, Some(event_str), false) {
eprintln!("unable to start tape backup job {} - {}", &job_id, err);
}
};

View File

@ -19,6 +19,7 @@ pub fn do_verification_job(
verification_job: VerificationJobConfig,
auth_id: &Authid,
schedule: Option<String>,
to_stdout: bool,
) -> Result<String, Error> {
let datastore = DataStore::lookup_datastore(&verification_job.store)?;
@ -36,7 +37,7 @@ pub fn do_verification_job(
&worker_type,
Some(job_id.clone()),
auth_id.clone(),
false,
to_stdout,
move |worker| {
job.start(&worker.upid().to_string())?;