From b364baf8ff8d00f12b896359bcb39e013551d146 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Tue, 7 Jul 2020 10:43:38 +0200 Subject: [PATCH] use new get_runtime_with_builder --- Cargo.toml | 2 +- src/backup.rs | 32 +++++++++++++++++++++----------- src/restore.rs | 12 ++++++++++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7431d7..f5449cd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,7 @@ cbindgen = "0.14.2" libc = "0.2" bytes = "0.5" proxmox = { version = "0.1.42", features = [ "sortable-macro", "api-macro" ] } -proxmox-backup = { git = "git://git.proxmox.com/git/proxmox-backup.git", tag = "v0.7.0" } +proxmox-backup = { git = "git://git.proxmox.com/git/proxmox-backup.git", tag = "v0.8.0" } #proxmox-backup = { path = "../proxmox-backup" } chrono = "0.4" # Date and time library for Rust anyhow = "1.0" diff --git a/src/backup.rs b/src/backup.rs index e6b120e..9c086e2 100644 --- a/src/backup.rs +++ b/src/backup.rs @@ -5,7 +5,9 @@ use once_cell::sync::OnceCell; use std::os::raw::c_int; use futures::future::{Future, Either, FutureExt}; +use tokio::runtime::Runtime; +use proxmox_backup::tools::runtime::get_runtime_with_builder; use proxmox_backup::backup::{CryptConfig, BackupManifest, load_and_decrypt_key}; use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupWriter}; @@ -16,7 +18,7 @@ use crate::commands::*; pub(crate) struct BackupTask { setup: BackupSetup, - runtime: tokio::runtime::Runtime, + runtime: Arc, crypt_config: Option>, writer: OnceCell>, last_manifest: OnceCell>, @@ -28,16 +30,11 @@ pub(crate) struct BackupTask { impl BackupTask { - pub fn new(setup: BackupSetup) -> Result { - - let mut builder = tokio::runtime::Builder::new(); - builder.threaded_scheduler(); - builder.enable_all(); - builder.max_threads(6); - builder.core_threads(4); - builder.thread_name("proxmox-backup-qemu-worker"); - - let runtime = builder.build()?; + /// Create a new instance, using the specified Runtime + /// + /// We keep a reference to the runtime - else the runtime can be + /// dropped and further connections fails. + pub fn with_runtime(setup: BackupSetup, runtime: Arc) -> Result { let crypt_config = match setup.keyfile { None => None, @@ -62,6 +59,19 @@ impl BackupTask { aborted: OnceCell::new() }) } + pub fn new(setup: BackupSetup) -> Result { + let runtime = get_runtime_with_builder(|| { + let mut builder = tokio::runtime::Builder::new(); + builder.threaded_scheduler(); + builder.enable_all(); + builder.max_threads(6); + builder.core_threads(4); + builder.thread_name("proxmox-backup-worker"); + builder + }); + Self::with_runtime(setup, runtime) + } + pub fn runtime(&self) -> tokio::runtime::Handle { self.runtime.handle().clone() } diff --git a/src/restore.rs b/src/restore.rs index 70c4dca..5a5667d 100644 --- a/src/restore.rs +++ b/src/restore.rs @@ -7,7 +7,7 @@ use anyhow::{format_err, bail, Error}; use once_cell::sync::OnceCell; use tokio::runtime::Runtime; -use proxmox_backup::tools::runtime::{get_runtime, block_in_place}; +use proxmox_backup::tools::runtime::{get_runtime_with_builder, block_in_place}; use proxmox_backup::backup::*; use proxmox_backup::client::{HttpClient, HttpClientOptions, BackupReader, RemoteChunkReader}; @@ -64,7 +64,15 @@ impl RestoreTask { } pub fn new(setup: BackupSetup) -> Result { - let runtime = get_runtime(); + let runtime = get_runtime_with_builder(|| { + let mut builder = tokio::runtime::Builder::new(); + builder.threaded_scheduler(); + builder.enable_all(); + builder.max_threads(6); + builder.core_threads(4); + builder.thread_name("proxmox-restore-worker"); + builder + }); Self::with_runtime(setup, runtime) }