@@ -3,10 +3,6 @@ use std::{future::Future, sync::Arc, time::Instant};
3
3
use futures:: stream:: FuturesUnordered ;
4
4
use time:: Duration ;
5
5
6
- #[ cfg( any(
7
- feature = "redis" ,
8
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
9
- ) ) ]
10
6
use time:: OffsetDateTime ;
11
7
12
8
use crate :: {
@@ -89,6 +85,11 @@ pub struct BroccoliQueueBuilder {
89
85
retry_failed : Option < bool > ,
90
86
/// Number of connections to maintain in the connection pool
91
87
pool_connections : Option < u8 > ,
88
+ /// Whether to enable message scheduling
89
+ ///
90
+ /// NOTE: If you enable this w/ rabbitmq, you will need to install the delayed-exchange plugin
91
+ /// https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq
92
+ enable_scheduling : Option < bool > ,
92
93
}
93
94
94
95
impl BroccoliQueueBuilder {
@@ -105,6 +106,7 @@ impl BroccoliQueueBuilder {
105
106
retry_attempts : None ,
106
107
retry_failed : None ,
107
108
pool_connections : None ,
109
+ enable_scheduling : None ,
108
110
}
109
111
}
110
112
@@ -133,6 +135,21 @@ impl BroccoliQueueBuilder {
133
135
self
134
136
}
135
137
138
+ /// Enables or disables message scheduling.
139
+ ///
140
+ /// NOTE: If you enable this w/ rabbitmq, you will need to install the delayed-exchange plugin
141
+ /// https://www.rabbitmq.com/blog/2015/04/16/scheduling-messages-with-rabbitmq
142
+ ///
143
+ /// # Arguments
144
+ /// * `enable_scheduling` - If true, message scheduling will be enabled.
145
+ ///
146
+ /// # Returns
147
+ /// The updated `BroccoliQueueBuilder` instance.
148
+ pub fn enable_scheduling ( mut self , enable_scheduling : bool ) -> Self {
149
+ self . enable_scheduling = Some ( enable_scheduling) ;
150
+ self
151
+ }
152
+
136
153
/// Builds the `BroccoliQueue` with the specified configuration.
137
154
///
138
155
/// # Returns
@@ -142,6 +159,7 @@ impl BroccoliQueueBuilder {
142
159
retry_attempts : self . retry_attempts ,
143
160
retry_failed : self . retry_failed ,
144
161
pool_connections : self . pool_connections ,
162
+ enable_scheduling : self . enable_scheduling ,
145
163
} ;
146
164
147
165
let broker = connect_to_broker ( & self . broker_url , Some ( config) )
@@ -209,16 +227,8 @@ pub struct PublishOptions {
209
227
pub ttl : Option < Duration > ,
210
228
/// Message priority level. This is a number between 1 and 5, where 5 is the lowest priority and 1 is the highest.
211
229
pub priority : Option < u8 > ,
212
- #[ cfg( any(
213
- feature = "redis" ,
214
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
215
- ) ) ]
216
230
/// Delay before the message is published
217
231
pub delay : Option < Duration > ,
218
- #[ cfg( any(
219
- feature = "redis" ,
220
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
221
- ) ) ]
222
232
/// Scheduled time for the message to be published
223
233
pub scheduled_at : Option < OffsetDateTime > ,
224
234
}
@@ -235,15 +245,7 @@ impl PublishOptions {
235
245
pub struct PublishOptionsBuilder {
236
246
ttl : Option < Duration > ,
237
247
priority : Option < u8 > ,
238
- #[ cfg( any(
239
- feature = "redis" ,
240
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
241
- ) ) ]
242
248
delay : Option < Duration > ,
243
- #[ cfg( any(
244
- feature = "redis" ,
245
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
246
- ) ) ]
247
249
scheduled_at : Option < OffsetDateTime > ,
248
250
}
249
251
@@ -253,15 +255,7 @@ impl PublishOptionsBuilder {
253
255
Self {
254
256
ttl : None ,
255
257
priority : None ,
256
- #[ cfg( any(
257
- feature = "redis" ,
258
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
259
- ) ) ]
260
258
delay : None ,
261
- #[ cfg( any(
262
- feature = "redis" ,
263
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
264
- ) ) ]
265
259
scheduled_at : None ,
266
260
}
267
261
}
@@ -273,20 +267,12 @@ impl PublishOptionsBuilder {
273
267
}
274
268
275
269
/// Sets a delay before the message is published.
276
- #[ cfg( any(
277
- feature = "redis" ,
278
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
279
- ) ) ]
280
270
pub fn delay ( mut self , duration : Duration ) -> Self {
281
271
self . delay = Some ( duration) ;
282
272
self
283
273
}
284
274
285
275
/// Sets a specific time for the message to be published.
286
- #[ cfg( any(
287
- feature = "redis" ,
288
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
289
- ) ) ]
290
276
pub fn schedule_at ( mut self , time : OffsetDateTime ) -> Self {
291
277
self . scheduled_at = Some ( time) ;
292
278
self
@@ -307,15 +293,7 @@ impl PublishOptionsBuilder {
307
293
PublishOptions {
308
294
ttl : self . ttl ,
309
295
priority : self . priority ,
310
- #[ cfg( any(
311
- feature = "redis" ,
312
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
313
- ) ) ]
314
296
delay : self . delay ,
315
- #[ cfg( any(
316
- feature = "redis" ,
317
- all( feature = "rabbitmq" , feature = "rabbitmq-delay" )
318
- ) ) ]
319
297
scheduled_at : self . scheduled_at ,
320
298
}
321
299
}
0 commit comments