Skip to main content

awa_model/
lib.rs

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