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