Factor out taskrun
This commit is contained in:
11
taskrun/Cargo.toml
Normal file
11
taskrun/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "taskrun"
|
||||
version = "0.0.1-a.0"
|
||||
authors = ["Dominik Werder <dominik.werder@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[dependencies]
|
||||
tokio = { version = "1.4.0", features = ["rt-multi-thread", "io-util", "net", "time", "sync", "fs"] }
|
||||
tracing = "0.1.25"
|
||||
tracing-subscriber = "0.2.17"
|
||||
err = { path = "../err" }
|
||||
24
taskrun/src/lib.rs
Normal file
24
taskrun/src/lib.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use err::Error;
|
||||
|
||||
pub fn run<T, F: std::future::Future<Output=Result<T, Error>>>(f: F) -> Result<T, Error> {
|
||||
tracing_init();
|
||||
tokio::runtime::Builder::new_multi_thread()
|
||||
.worker_threads(12)
|
||||
.max_blocking_threads(256)
|
||||
.enable_all()
|
||||
.build()
|
||||
.unwrap()
|
||||
.block_on(async {
|
||||
f.await
|
||||
})
|
||||
}
|
||||
|
||||
pub fn tracing_init() {
|
||||
tracing_subscriber::fmt()
|
||||
//.with_timer(tracing_subscriber::fmt::time::uptime())
|
||||
.with_target(true)
|
||||
.with_thread_names(true)
|
||||
//.with_max_level(tracing::Level::INFO)
|
||||
.with_env_filter(tracing_subscriber::EnvFilter::new("info,retrieval=trace,disk=trace,tokio_postgres=info"))
|
||||
.init();
|
||||
}
|
||||
Reference in New Issue
Block a user