@@ -32,13 +32,15 @@ enum ErrorKind {
32
32
impl std:: error:: Error for ClientError { }
33
33
34
34
pub fn create_redis_pool ( ) -> Result < ConnectionManager , ClientError > {
35
+ block_on ( create_async_redis_pool ( ) )
36
+ }
37
+
38
+ pub async fn create_async_redis_pool ( ) -> Result < ConnectionManager , ClientError > {
35
39
let redis_url =
36
40
& env:: var ( & REDIS_URL_ENV . to_owned ( ) ) . unwrap_or_else ( |_| REDIS_URL_DEFAULT . to_owned ( ) ) ;
37
41
// Note: this connection is multiplexed. Users of this object will call clone(), but the same underlying connection will be used.
38
42
// https://docs.rs/redis/latest/redis/aio/struct.ConnectionManager.html
39
- match block_on ( ConnectionManager :: new (
40
- redis:: Client :: open ( ( * redis_url) . clone ( ) ) . unwrap ( ) ,
41
- ) ) {
43
+ match ConnectionManager :: new ( redis:: Client :: open ( ( * redis_url) . clone ( ) ) . unwrap ( ) ) . await {
42
44
Ok ( pool) => Ok ( pool) ,
43
45
Err ( err) => Err ( ClientError {
44
46
kind : ErrorKind :: Redis ( err) ,
@@ -225,21 +227,41 @@ impl Client {
225
227
}
226
228
227
229
pub fn perform_in ( & self , interval : Duration , job : Job ) -> Result < ( ) , ClientError > {
228
- let interval: f64 = interval. whole_seconds ( ) as f64 ;
229
- block_on ( self . raw_push ( & [ job] , self . calc_at ( interval) ) )
230
+ block_on ( self . perform_in_async ( interval, job) )
230
231
}
231
232
232
233
pub fn perform_at ( & self , datetime : OffsetDateTime , job : Job ) -> Result < ( ) , ClientError > {
233
- let timestamp: f64 = datetime. unix_timestamp ( ) as f64 ;
234
- block_on ( self . raw_push ( & [ job] , self . calc_at ( timestamp) ) )
234
+ block_on ( self . perform_at_async ( datetime, job) )
235
235
}
236
236
237
237
pub fn push ( & self , job : Job ) -> Result < ( ) , ClientError > {
238
- block_on ( self . raw_push ( & [ job] , None ) )
238
+ block_on ( self . push_async ( job) )
239
239
}
240
240
241
241
pub fn push_bulk ( & self , jobs : & [ Job ] ) -> Result < ( ) , ClientError > {
242
- block_on ( self . raw_push ( jobs, None ) )
242
+ block_on ( self . push_bulk_async ( jobs) )
243
+ }
244
+
245
+ pub async fn perform_in_async ( & self , interval : Duration , job : Job ) -> Result < ( ) , ClientError > {
246
+ let interval: f64 = interval. whole_seconds ( ) as f64 ;
247
+ self . raw_push ( & [ job] , self . calc_at ( interval) ) . await
248
+ }
249
+
250
+ pub async fn perform_at_async (
251
+ & self ,
252
+ datetime : OffsetDateTime ,
253
+ job : Job ,
254
+ ) -> Result < ( ) , ClientError > {
255
+ let timestamp: f64 = datetime. unix_timestamp ( ) as f64 ;
256
+ self . raw_push ( & [ job] , self . calc_at ( timestamp) ) . await
257
+ }
258
+
259
+ pub async fn push_async ( & self , job : Job ) -> Result < ( ) , ClientError > {
260
+ self . raw_push ( & [ job] , None ) . await
261
+ }
262
+
263
+ pub async fn push_bulk_async ( & self , jobs : & [ Job ] ) -> Result < ( ) , ClientError > {
264
+ self . raw_push ( jobs, None ) . await
243
265
}
244
266
245
267
async fn raw_push ( & self , payloads : & [ Job ] , at : Option < f64 > ) -> Result < ( ) , ClientError > {
0 commit comments