qrush_engine/cron/
cron_job.rs

1// src/cron/cron_job.rs
2use async_trait::async_trait;
3use serde::{Deserialize, Serialize};
4use crate::job::Job;
5/// NOTE: `timezone()` must return a valid IANA TZ (e.g., "UTC", "Asia/Kolkata")
6
7/// Trait for jobs that can be scheduled with cron expressions
8#[async_trait]
9pub trait CronJob: Job + Send + Sync {
10    /// Cron expression (e.g., "0 */5 * * * *" for every 5 minutes)
11    fn cron_expression(&self) -> &'static str;
12    
13    /// Unique identifier for this cron job
14    fn cron_id(&self) -> &'static str;
15    
16    /// Whether this cron job is enabled
17    fn enabled(&self) -> bool {
18        true
19    }
20    
21    /// Timezone for cron execution (default UTC)
22    fn timezone(&self) -> &'static str {
23        "UTC"
24    }
25}
26
27/// Metadata for storing cron jobs in Redis
28#[derive(Debug, Serialize, Deserialize, Clone)]
29pub struct CronJobMeta {
30    pub id: String,
31    pub name: String,
32    pub queue: String,
33    pub cron_expression: String,
34    pub timezone: String,
35    pub enabled: bool,
36    /// RFC3339 (UTC). May be absent on first run.
37    #[serde(default)]
38    pub last_run: Option<String>,
39    pub next_run: String,
40    pub created_at: String,
41    pub payload: String, // Serialized job data
42}