tokio_cron_scheduler/job/
to_code.rs

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
use crate::context::Context;
use crate::job::JobToRunAsync;
use crate::{JobSchedulerError, OnJobNotification};
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use tokio::sync::RwLock;
use uuid::Uuid;

pub type PinnedGetFuture<T> =
    Pin<Box<dyn Future<Output = Result<Option<Arc<RwLock<T>>>, JobSchedulerError>> + Send>>;

pub trait ToCode<T>
where
    T: Send,
{
    fn init(
        &mut self,
        context: &Context,
    ) -> Pin<Box<dyn Future<Output = Result<(), JobSchedulerError>> + Send>>;

    fn get(&mut self, uuid: Uuid) -> PinnedGetFuture<T>;
}

pub trait JobCode: ToCode<Box<JobToRunAsync>> + Send {}

pub trait NotificationCode: ToCode<Box<OnJobNotification>> {}