Skip to main content

awa_model/
lib.rs

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