use new get_runtime_with_builder

This commit is contained in:
Dietmar Maurer 2020-07-07 10:43:38 +02:00
parent 8fc4b1f92d
commit b364baf8ff
3 changed files with 32 additions and 14 deletions

View File

@ -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"

View File

@ -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<Runtime>,
crypt_config: Option<Arc<CryptConfig>>,
writer: OnceCell<Arc<BackupWriter>>,
last_manifest: OnceCell<Arc<BackupManifest>>,
@ -28,16 +30,11 @@ pub(crate) struct BackupTask {
impl BackupTask {
pub fn new(setup: BackupSetup) -> Result<Self, Error> {
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<Runtime>) -> Result<Self, Error> {
let crypt_config = match setup.keyfile {
None => None,
@ -62,6 +59,19 @@ impl BackupTask {
aborted: OnceCell::new() })
}
pub fn new(setup: BackupSetup) -> Result<Self, Error> {
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()
}

View File

@ -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<Self, Error> {
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)
}