|
@ -1,9 +1,11 @@ |
|
|
|
|
|
use crate::async_utils::sleep;
|
|
|
use crate::loggers::Logger;
|
|
|
use crate::loggers::Logger;
|
|
|
use crate::symbols::Symbol;
|
|
|
use crate::symbols::Symbol;
|
|
|
use async_trait::async_trait;
|
|
|
use async_trait::async_trait;
|
|
|
use std::error::Error;
|
|
|
use std::error::Error;
|
|
|
use std::fmt;
|
|
|
use std::fmt;
|
|
|
use std::fmt::Debug;
|
|
|
use std::fmt::Debug;
|
|
|
|
|
|
use std::time::Duration;
|
|
|
|
|
|
|
|
|
#[async_trait(?Send)]
|
|
|
#[async_trait(?Send)]
|
|
|
pub trait SymbolRunner {
|
|
|
pub trait SymbolRunner {
|
|
@ -96,6 +98,41 @@ impl SymbolRunner for InitializingSymbolRunner { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
|
pub struct DelayingSymbolRunner<R>(R);
|
|
|
|
|
|
|
|
|
|
|
|
impl<R> DelayingSymbolRunner<R> {
|
|
|
|
|
|
pub fn new(symbol_runner: R) -> Self {
|
|
|
|
|
|
Self(symbol_runner)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[async_trait(?Send)]
|
|
|
|
|
|
impl<R> SymbolRunner for DelayingSymbolRunner<R>
|
|
|
|
|
|
where
|
|
|
|
|
|
R: SymbolRunner,
|
|
|
|
|
|
{
|
|
|
|
|
|
async fn run_symbol<S: Symbol + Debug, L: Logger>(
|
|
|
|
|
|
&self,
|
|
|
|
|
|
symbol: &S,
|
|
|
|
|
|
logger: &L,
|
|
|
|
|
|
force: bool,
|
|
|
|
|
|
) -> Result<bool, Box<dyn Error>> {
|
|
|
|
|
|
sleep(Duration::from_millis(
|
|
|
|
|
|
(((std::time::SystemTime::now()
|
|
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
|
|
.unwrap()
|
|
|
|
|
|
.subsec_micros()
|
|
|
|
|
|
% 20) as f32
|
|
|
|
|
|
/ 2.0)
|
|
|
|
|
|
.exp()
|
|
|
|
|
|
/ 8.0) as u64,
|
|
|
|
|
|
))
|
|
|
|
|
|
.await;
|
|
|
|
|
|
self.0.run_symbol(symbol, logger, force).await
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
pub struct DrySymbolRunner;
|
|
|
pub struct DrySymbolRunner;
|
|
|
|
|
|
|
|
|