From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8624B1FF13B for ; Tue, 27 Jan 2026 10:17:28 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 49C261D778; Tue, 27 Jan 2026 10:17:52 +0100 (CET) Date: Tue, 27 Jan 2026 10:17:18 +0100 Message-Id: From: "Lukas Wagner" To: "Proxmox Datacenter Manager development discussion" , "Shan Shaji" Mime-Version: 1.0 X-Mailer: aerc 0.21.0-0-g5549850facc2-dirty References: <20260123172910.244121-1-s.shaji@proxmox.com> <20260123172910.244121-2-s.shaji@proxmox.com> In-Reply-To: <20260123172910.244121-2-s.shaji@proxmox.com> X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1769505374008 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.038 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: Re: [pdm-devel] [PATCH datacenter-manager 1/3] cli: admin: make cli handling async X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" Hi Shan, thanks for these patches! Some comments inline. On Fri Jan 23, 2026 at 6:29 PM CET, Shan Shaji wrote: > The acme API methods internally create workers to process API requests. > An error was thrown if the methods invoked without initializing the > worker tasks. > > Since `init_worker_tasks` needs to be called from an async runtime. > Moved the content of the main function to async `run` function and > wrapped using `proxmox_async::runtime::main`, which creates a Tokio > runtime. > > Signed-off-by: Shan Shaji > --- > cli/admin/Cargo.toml | 3 +++ > cli/admin/src/main.rs | 51 ++++++++++++++++++++++++++----------------- > 2 files changed, 34 insertions(+), 20 deletions(-) > > diff --git a/cli/admin/Cargo.toml b/cli/admin/Cargo.toml > index 0dec423..e566b39 100644 > --- a/cli/admin/Cargo.toml > +++ b/cli/admin/Cargo.toml > @@ -19,6 +19,9 @@ proxmox-product-config.workspace = true > proxmox-router = { workspace = true, features = [ "cli" ], default-features = false } > proxmox-schema = { workspace = true, features = [ "api-macro" ] } > proxmox-access-control.workspace = true > +proxmox-rest-server.workspace = true > +proxmox-sys.workspace = true > +proxmox-daemon.workspace = true > > pdm-api-types.workspace = true > pdm-config.workspace = true > diff --git a/cli/admin/src/main.rs b/cli/admin/src/main.rs > index f698fa2..bcaa0a6 100644 > --- a/cli/admin/src/main.rs > +++ b/cli/admin/src/main.rs > @@ -1,35 +1,31 @@ > +use anyhow::Error; > use serde_json::{json, Value}; > > use proxmox_router::cli::{ > - default_table_format_options, format_and_print_result_full, get_output_format, run_cli_command, > - CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT, > + default_table_format_options, format_and_print_result_full, get_output_format, > + run_async_cli_command, CliCommand, CliCommandMap, CliEnvironment, ColumnConfig, OUTPUT_FORMAT, > }; > use proxmox_router::RpcEnvironment; > - > use proxmox_schema::api; > +use proxmox_sys::fs::CreateOptions; > > mod remotes; > mod support_status; > > -fn main() { > - //pbs_tools::setup_libc_malloc_opts(); // TODO: move from PBS to proxmox-sys and uncomment > - > - let api_user = pdm_config::api_user().expect("cannot get api user"); > - let priv_user = pdm_config::priv_user().expect("cannot get privileged user"); > - proxmox_product_config::init(api_user, priv_user); > +async fn run() -> Result<(), Error> { > + let api_user = pdm_config::api_user()?; > + let priv_user = pdm_config::priv_user()?; if you convert these .expect("...") calls to errors and bubble them up, if would be nice if you used .context() from anyhow to preserve the error messages. E.g.: let priv_user = pdm_config::priv_user().context("could not get privileged user")?; > > + proxmox_product_config::init(api_user.clone(), priv_user); > proxmox_access_control::init::init( > &pdm_api_types::AccessControlConfig, > pdm_buildcfg::configdir!("/access"), > - ) > - .expect("failed to setup access control config"); > - > + )?; > proxmox_log::Logger::from_env("PDM_LOG", proxmox_log::LevelFilter::INFO) > .stderr() > - .init() > - .expect("failed to set up logger"); > + .init()?; > > - server::context::init().expect("could not set up server context"); > + server::context::init()?; > > let cmd_def = CliCommandMap::new() > .insert("remote", remotes::cli()) > @@ -40,14 +36,29 @@ fn main() { > .insert("support-status", support_status::cli()) > .insert("versions", CliCommand::new(&API_METHOD_GET_VERSIONS)); > > + let args: Vec = std::env::args().collect(); > + let avoid_init = args.len() >= 2 && (args[1] == "bashcomplete" || args[1] == "printdoc"); > + > + if !avoid_init { > + let file_opts = CreateOptions::new().owner(api_user.uid).group(api_user.gid); > + proxmox_rest_server::init_worker_tasks(pdm_buildcfg::PDM_LOG_DIR_M!().into(), file_opts)?; > + > + let mut command_sock = proxmox_daemon::command_socket::CommandSocket::new(api_user.gid); > + proxmox_rest_server::register_task_control_commands(&mut command_sock)?; > + command_sock.spawn(proxmox_rest_server::last_worker_future())?; > + } > + > let mut rpcenv = CliEnvironment::new(); > rpcenv.set_auth_id(Some("root@pam".into())); > > - run_cli_command( > - cmd_def, > - rpcenv, > - Some(|future| proxmox_async::runtime::main(future)), > - ); > + run_async_cli_command(cmd_def, rpcenv).await; > + > + Ok(()) > +} > + > +fn main() -> Result<(), Error> { > + //pbs_tools::setup_libc_malloc_opts(); // TODO: move from PBS to proxmox-sys and uncomment > + proxmox_async::runtime::main(run()) > } > > #[api( _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel