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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//! A SQLite-based task queue library that allows running background jobs without requiring
//! external dependencies.
//!
//! ```no_run
//! # use std::sync::Arc;
//! # use std::path::Path;
//! # use serde::{Deserialize, Serialize};
//! # use serde_json::json;
//! use effectum::{Error, Job, JobState, JobRunner, RunningJob, Queue, Worker};
//!
//! #[derive(Debug)]
//! pub struct JobContext {
//! // database pool or other things here
//! }
//!
//! #[derive(Serialize, Deserialize)]
//! struct RemindMePayload {
//! email: String,
//! message: String,
//! }
//!
//! async fn remind_me_job(job: RunningJob, context: Arc<JobContext>) -> Result<(), Error> {
//! let payload: RemindMePayload = job.json_payload()?;
//! // do something with the job
//! Ok(())
//! }
//!
//! #[tokio::main(flavor = "current_thread")]
//! async fn main() -> Result<(), Error> {
//! // Create a queue
//! let queue = Queue::new(Path::new("effectum.db")).await?;
//!
//! // Define a job type for the queue.
//! let remind_job = JobRunner::builder("remind_me", remind_me_job).build();
//!
//! let context = Arc::new(JobContext{
//! // database pool or other things here
//! });
//!
//! // Create a worker to run jobs.
//! let worker = Worker::builder(&queue, context)
//! .max_concurrency(10)
//! .jobs([remind_job])
//! .build();
//!
//! // Submit a job to the queue.
//! let job_id = Job::builder("remind_me")
//! .run_at(time::OffsetDateTime::now_utc() + std::time::Duration::from_secs(10))
//! .json_payload(&RemindMePayload {
//! email: "me@example.com".to_string(),
//! message: "Time to go!".to_string()
//! })?
//! .add_to(&queue)
//! .await?;
//!
//! // See what's happening with the job.
//! let status = queue.get_job_status(job_id).await?;
//! assert_eq!(status.state, JobState::Pending);
//!
//! // Do other stuff...
//!
//! Ok(())
//! }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use *;
pub use ;
pub use ;
pub type SmartString = SmartString;
/// How to treat jobs which are already marked as running when the queue starts.
/// This accounts for cases where the process is restarted unexpectedly.