Skip to main content

wabot_feature_async/
handler.rs

1//! Command + cron handler traits.
2//!
3//! The macro-generated dispatch wraps user methods in these type-erased
4//! `Arc<dyn Fn>` invocation closures so the runtime can call any
5//! handler by `command_name` without knowing the concrete arg type.
6
7use std::future::Future;
8use std::pin::Pin;
9use std::sync::Arc;
10
11use crate::types::AsyncError;
12
13/// Boxed async invoke closure: takes the JSON-encoded command data and
14/// runs the handler. Returns `Ok(())` on success, `Err` on failure.
15pub type CommandInvokeFn = Arc<
16    dyn Fn(
17            wabot_core::injection::Container,
18            serde_json::Value,
19        ) -> Pin<Box<dyn Future<Output = Result<(), AsyncError>> + Send>>
20        + Send
21        + Sync,
22>;
23
24/// Boxed async invoke closure for cron handlers — no args.
25pub type CronInvokeFn = Arc<
26    dyn Fn(
27            wabot_core::injection::Container,
28        ) -> Pin<Box<dyn Future<Output = Result<(), AsyncError>> + Send>>
29        + Send
30        + Sync,
31>;
32
33/// Metadata + invoker for one registered command handler.
34#[derive(Clone)]
35pub struct CommandHandlerEntry {
36    pub command_name: String,
37    pub options: crate::types::JobOptions,
38    pub dedup: Option<crate::types::DedupConfig>,
39    pub invoke: CommandInvokeFn,
40}
41
42/// Metadata + invoker for one registered cron handler.
43#[derive(Clone)]
44pub struct CronHandlerEntry {
45    pub name: String,
46    pub command_name: String,
47    pub cron: String,
48    pub enabled: bool,
49    pub options: crate::types::JobOptions,
50    pub max_running_jobs: Option<u32>,
51    pub misfire_policy: Option<crate::types::MisfirePolicy>,
52    pub invoke: CronInvokeFn,
53}