cron_task_scheduler/
models.rs1use async_trait::async_trait;
2use chrono::{DateTime, Utc};
3use std::collections::HashMap;
4use std::fmt::Debug;
5
6#[derive(Debug, Clone)]
7pub struct TaskContext {
8 pub scheduled_time: DateTime<Utc>,
9 pub actual_time: DateTime<Utc>,
10 pub weight: i8, #[allow(dead_code)]
12 pub metadata: HashMap<String, String>,
13}
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq)]
16pub enum TaskType {
17 Async, Blocking, }
20
21#[async_trait]
22pub trait ReactiveTask: Send + Sync + Debug {
23 fn id(&self) -> &str;
24 fn task_type(&self) -> TaskType {
25 TaskType::Async
26 }
27 async fn execute(
28 &self,
29 context: TaskContext,
30 ) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum ExecutionPolicy {
35 SkipIfRunning,
37 Parallel,
39 #[allow(dead_code)]
41 Sequential,
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
45pub enum SchedulingPolicy {
46 FirstInFirstOut,
47 Priority,
48 Fair,
49 Delayed,
50 RateLimited,
51}