1use std::future::Future;
4
5use futures::Stream;
6
7use crate::{
8 common::NextPageToken,
9 executions::{
10 FailedExecution, InProgressExecution, ReadyExecution, StartedExecution, SucceededExecution,
11 },
12 jobs::{CancelledJob, JobDetails, JobFilters, JobId, JobOrderBy, JobType, NewJob},
13 schedules::{
14 PendingSchedule, ScheduleDefinition, ScheduleDetails, ScheduleFilters, ScheduleId,
15 ScheduleOrderBy, StoppedSchedule,
16 },
17};
18
19pub mod common;
20pub mod executions;
21pub mod executors;
22pub mod jobs;
23pub mod schedules;
24
25#[cfg(feature = "test")]
26pub mod test;
27
28pub trait Backend: Send + Sync + 'static {
33 type Error: core::error::Error + Send + Sync + 'static;
35
36 fn add_job_types(
38 &self,
39 job_types: &[JobType],
40 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
41 fn list_job_types(&self) -> impl Future<Output = Result<Vec<JobType>, Self::Error>> + Send;
43
44 fn add_jobs(
52 &self,
53 jobs: &[NewJob],
54 if_not_exists: Option<JobFilters>,
55 ) -> impl Future<Output = Result<Vec<JobId>, Self::Error>> + Send;
56
57 fn list_jobs(
59 &self,
60 filters: JobFilters,
61 order_by: Option<JobOrderBy>,
62 page_size: u32,
63 page_token: Option<NextPageToken>,
64 ) -> impl Future<Output = Result<(Vec<JobDetails>, Option<NextPageToken>), Self::Error>> + Send;
65
66 fn count_jobs(
68 &self,
69 filters: JobFilters,
70 ) -> impl Future<Output = Result<u64, Self::Error>> + Send;
71
72 fn cancel_jobs(
75 &self,
76 filters: JobFilters,
77 ) -> impl Future<Output = Result<Vec<CancelledJob>, Self::Error>> + Send;
78
79 fn add_schedules(
85 &self,
86 schedules: &[ScheduleDefinition],
87 if_not_exists: Option<ScheduleFilters>,
88 ) -> impl Future<Output = Result<Vec<ScheduleId>, Self::Error>> + Send;
89
90 fn list_schedules(
92 &self,
93 filters: ScheduleFilters,
94 order_by: Option<ScheduleOrderBy>,
95 page_size: u32,
96 page_token: Option<NextPageToken>,
97 ) -> impl Future<Output = Result<(Vec<ScheduleDetails>, Option<NextPageToken>), Self::Error>> + Send;
98
99 fn count_schedules(
101 &self,
102 filters: ScheduleFilters,
103 ) -> impl Future<Output = Result<u64, Self::Error>> + Send;
104
105 fn stop_schedules(
108 &self,
109 filters: ScheduleFilters,
110 ) -> impl Future<Output = Result<Vec<StoppedSchedule>, Self::Error>> + Send;
111
112 fn ready_executions(
119 &self,
120 ) -> impl Stream<Item = Result<Vec<ReadyExecution>, Self::Error>> + Send;
121
122 fn wait_for_ready_executions(&self) -> impl Future<Output = Result<(), Self::Error>> + Send;
124
125 fn in_progress_executions(
130 &self,
131 ) -> impl Stream<Item = Result<Vec<InProgressExecution>, Self::Error>> + Send;
132
133 fn executions_started(
137 &self,
138 executions: &[StartedExecution],
139 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
140
141 fn executions_succeeded(
143 &self,
144 executions: &[SucceededExecution],
145 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
146
147 fn executions_failed(
149 &self,
150 executions: &[FailedExecution],
151 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
152
153 fn executions_retried(
157 &self,
158 executions: &[FailedExecution],
159 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
160
161 fn pending_schedules(
164 &self,
165 ) -> impl Stream<Item = Result<Vec<PendingSchedule>, Self::Error>> + Send;
166
167 fn wait_for_pending_schedules(&self) -> impl Future<Output = Result<(), Self::Error>> + Send;
169
170 fn delete_history(
177 &self,
178 before: std::time::SystemTime,
179 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
180}