Commit e35db95a authored by PERE Alexandre's avatar PERE Alexandre

Merge branch '16-change-timers-implementation' into 'develop'

Resolve "Change timers implementation"

See merge request !14
parents 9c89cd51 a9b77ff2
......@@ -36,6 +36,8 @@ tracing-subscriber = "0.1.5"
tracing-attributes = "0.1.5"
tracing-futures = {version = "0.1.0", features=["futures-preview"]}
derivative = "1.0.3"
arrayvec = "0.5.1"
lazy_static = "1.4.0"
[lib]
name="liborchestra"
......
......@@ -12,6 +12,14 @@ use regex;
use super::CMPCONF_RPATH;
use tracing::{self, warn, debug};
use super::commons::OutputBuf;
use super::timer::TimerHandle;
//------------------------------------------------------------------------------------------- STATIC
lazy_static! {
pub static ref TIMER: TimerHandle = TimerHandle::spawn().expect("Failed to spawn timer.");
}
//------------------------------------------------------------------------------------------- ERRORS
......@@ -45,17 +53,8 @@ impl fmt::Display for Error {
macro_rules! async_sleep {
($dur: expr) => {
{
let (tx, rx) = oneshot::channel();
thread::spawn(move || {
thread::sleep($dur);
tx.send(()).unwrap();
});
use tracing_futures::Instrument;
use tracing::trace_span;
rx.instrument(trace_span!("async_sleep!"))
.await
.unwrap();
use crate::misc::TIMER;
(*TIMER).async_sleep($dur).await.unwrap();
}
};
}
......@@ -72,7 +71,7 @@ macro_rules! await_wouldblock_io {
loop{
match $expr {
Err(ref e) if e.kind() == std::io::ErrorKind::WouldBlock => {
async_sleep!(std::time::Duration::from_nanos(1))
async_sleep!(std::time::Duration::from_millis(2))
}
res => break res,
}
......@@ -93,10 +92,10 @@ macro_rules! await_wouldblock_ssh {
loop{
match $expr {
Err(ref e) if e.code() == -37 => {
async_sleep!(std::time::Duration::from_nanos(1))
async_sleep!(std::time::Duration::from_millis(2))
}
Err(ref e) if e.code() == -21 => {
async_sleep!(std::time::Duration::from_nanos(1))
async_sleep!(std::time::Duration::from_millis(2))
}
res => break res,
}
......@@ -124,7 +123,7 @@ macro_rules! await_retry_n_ssh {
}
$(
else if e.code() == $code as i32 {
async_sleep!(std::time::Duration::from_nanos(1));
async_sleep!(std::time::Duration::from_millis(2));
i += 1;
}
)*
......@@ -151,7 +150,7 @@ macro_rules! await_retry_ssh {
match $expr {
Err(e) => {
$( if e.code() == $code as i32 {
async_sleep!(std::time::Duration::from_nanos(1));
async_sleep!(std::time::Duration::from_millis(2));
} else )*
{
break Err(e)
......@@ -184,7 +183,7 @@ macro_rules! await_retry_n {
break Err(e)
}
else{
async_sleep!(std::time::Duration::from_nanos(1));
async_sleep!(std::time::Duration::from_millis(2));
i += 1;
}
}
......
......@@ -275,11 +275,14 @@ extern crate ssh2;
extern crate dirs;
extern crate libc;
extern crate chrono;
extern crate arrayvec;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate derivative;
#[macro_use]
extern crate lazy_static;
//------------------------------------------------------------------------------------------ MODULES
......@@ -291,6 +294,7 @@ pub mod repository;
pub mod primitives;
pub mod scheduler;
pub mod commons;
pub mod timer;
#[macro_use]
pub mod error;
......
This diff is collapsed.
......@@ -32,7 +32,6 @@ lazy_static!{
pub static ref NO_COLORS: bool = env::var("NO_COLOR").is_ok();
}
//-------------------------------------------------------------------------------------------- MACRO
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment