Skip to main content

awa_model/
lib.rs

1pub mod admin;
2pub mod cron;
3pub mod error;
4pub mod insert;
5pub mod job;
6pub mod kind;
7pub mod migrations;
8pub mod unique;
9
10// Re-exports for ergonomics
11pub use cron::{CronJobRow, PeriodicJob, PeriodicJobBuilder};
12pub use error::AwaError;
13pub use insert::{insert, insert_many, insert_many_copy, insert_many_copy_from_pool, insert_with};
14pub use job::{InsertOpts, InsertParams, JobRow, JobState, UniqueOpts};
15
16// Re-export the derive macro
17pub use awa_macros::JobArgs;
18
19/// Trait for typed job arguments.
20///
21/// Implement this trait (or use `#[derive(JobArgs)]`) to define a job type.
22/// The `kind()` method returns the snake_case kind string that identifies
23/// this job type across languages.
24pub trait JobArgs: serde::Serialize {
25    /// The kind string for this job type (e.g., "send_email").
26    fn kind() -> &'static str
27    where
28        Self: Sized;
29
30    /// Get the kind string for an instance.
31    fn kind_str(&self) -> &'static str
32    where
33        Self: Sized,
34    {
35        Self::kind()
36    }
37
38    /// Serialize to JSON value.
39    fn to_args(&self) -> Result<serde_json::Value, serde_json::Error> {
40        serde_json::to_value(self)
41    }
42}