1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use barley_runtime::prelude::*;
use tokio::time::{sleep, Duration};



pub struct Sleep {
    duration: Duration,
}

impl Sleep {
    pub fn new(duration: Duration) -> Self {
        Self {
            duration
        }
    }
}

#[async_trait]
impl Action for Sleep {
    async fn check(&self, _ctx: Arc<RwLock<Context>>) -> Result<bool> {
        Ok(false)
    }

    async fn perform(&self, _ctx: Arc<RwLock<Context>>) -> Result<Option<ActionOutput>> {
        sleep(self.duration).await;

        Ok(None)
    }

    async fn rollback(&self, _ctx: Arc<RwLock<Context>>) -> Result<()> {
        Ok(())
    }

    fn display_name(&self) -> String {
        format!("Sleep for {:?}", self.duration)
    }
}