Skip to main content

pgqueue_macros/
lib.rs

1//! Procedural macros for the `pgqueue` crate.
2//!
3//! Do not depend on this crate directly; use the re-export at `pgqueue::job`.
4
5use proc_macro::TokenStream;
6
7mod attrs;
8mod expand;
9
10/// Marks an `async fn` as a pgqueue job handler.
11///
12/// The accepted attributes and the signature contract are documented on the
13/// re-export this is used through, `pgqueue::job`.
14#[proc_macro_attribute]
15pub fn job(attr: TokenStream, item: TokenStream) -> TokenStream {
16    expand::expand_job(attr.into(), item.into()).unwrap_or_else(syn::Error::into_compile_error).into()
17}
18
19/// Marks an `async fn` as a pgqueue cron job, run on the given schedule.
20///
21/// The first argument is the cron expression; its syntax and whether it can
22/// ever produce a UTC occurrence are checked at compile time. The rest are the
23/// same configuration attributes as `job`. Cron functions take no payload —
24/// every parameter is an extractor.
25///
26/// The accepted attributes are documented on the re-export this is used
27/// through, `pgqueue::cron`.
28#[proc_macro_attribute]
29pub fn cron(attr: TokenStream, item: TokenStream) -> TokenStream {
30    expand::expand_cron(attr.into(), item.into()).unwrap_or_else(syn::Error::into_compile_error).into()
31}