1#![doc = include_str!("../README.md")]
2#![forbid(unsafe_code)]
3#![warn(clippy::all, missing_docs, nonstandard_style, future_incompatible)]
4
5mod error;
6mod listener;
7mod macros;
8mod next_step;
9mod task;
10mod traits;
11mod util;
12mod worker;
13
14pub use error::{Error, Result, StepError, StepResult};
15pub use next_step::NextStep;
16pub use traits::{Scheduler, Step};
17pub use worker::Worker;
18
19use chrono::{DateTime, Utc};
20use sqlx::{types::Uuid, PgExecutor};
21use std::time::Duration;
22
23const LOST_CONNECTION_SLEEP: Duration = Duration::from_secs(1);
24
25pub async fn enqueue<'e>(db: impl PgExecutor<'e>, task: &impl Scheduler) -> Result<Uuid> {
27 task.enqueue(db).await
28}
29
30pub async fn delay<'e>(
32 db: impl PgExecutor<'e>,
33 task: &impl Scheduler,
34 delay: Duration,
35) -> Result<Uuid> {
36 task.delay(db, delay).await
37}
38
39pub async fn schedule<'e>(
41 db: impl PgExecutor<'e>,
42 task: &impl Scheduler,
43 at: DateTime<Utc>,
44) -> Result<Uuid> {
45 task.schedule(db, at).await
46}