1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! # Backyard Core
//!
//! Core traits and types for the Backyard async job queue.
//!
//! This crate provides the fundamental abstractions that make Backyard backend-agnostic:
//! - [`Job`] trait for defining background jobs
//! - [`Queue`] trait for implementing backends (SQLite, Redis, etc.)
//! - [`WorkerPool`] for processing jobs with Tokio
//!
//! ## Quick Start
//!
//! Define a job by implementing [`Job`]:
//!
//! ```ignore
//! use backyard_core::{Job, JobContext, Result};
//! use async_trait::async_trait;
//! use serde::{Serialize, Deserialize};
//!
//! #[derive(Serialize, Deserialize)]
//! struct SendEmail {
//! to: String,
//! }
//!
//! #[async_trait]
//! impl Job for SendEmail {
//! const NAME: &'static str = "SendEmail";
//!
//! async fn execute(self, ctx: &JobContext) -> Result<()> {
//! println!("Sending email to {}", self.to);
//! Ok(())
//! }
//! }
//! ```
//!
//! Then use with a backend like `backyard-sqlite`:
//!
//! ```ignore
//! use backyard_sqlite::SqliteQueue;
//! use backyard_core::WorkerBuilder;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! let queue = SqliteQueue::new(Default::default()).await?;
//!
//! // Enqueue a job
//! let job = SendEmail { to: "user@example.com".into() };
//! let payload = serde_json::to_vec(&job)?;
//! let req = backyard_core::queue::EnqueueRequest {
//! job_type: SendEmail::NAME.to_string(),
//! queue: "default".to_string(),
//! payload,
//! max_retries: 3,
//! priority: 0,
//! scheduled_at: chrono::Utc::now(),
//! };
//! queue.push(req).await?;
//!
//! // Run the worker
//! WorkerBuilder::new(queue)
//! .concurrency(10)
//! .run()
//! .await?;
//!
//! Ok(())
//! }
//! ```
pub use ;
pub use ;
pub use JobOptions;
pub use Queue;
pub use build_dispatch_table;
pub use ;
pub use inventory;