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