@@ -13,7 +13,7 @@ use time::Duration;
13
13
14
14
use super :: utils;
15
15
16
- /// SurrealDB state struct
16
+ /// ` SurrealDB` state struct
17
17
pub struct SurrealDBBroker {
18
18
pub ( crate ) db : Option < Surreal < Any > > ,
19
19
pub ( crate ) connected : bool ,
@@ -22,7 +22,7 @@ pub struct SurrealDBBroker {
22
22
23
23
#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
24
24
pub ( crate ) struct InternalSurrealDBBrokerMessage {
25
- /// Actual record id in surrealDB (topicname,task_id)
25
+ /// Actual record id in surrealDB (` topicname,task_id` )
26
26
pub id : RecordId ,
27
27
/// Unique identifier for the message (external version, without table name)
28
28
pub task_id : String ,
@@ -86,7 +86,7 @@ impl Broker for SurrealDBBroker {
86
86
///
87
87
///
88
88
async fn connect ( & mut self , broker_url : & str ) -> Result < ( ) , BroccoliError > {
89
- let db = SurrealDBBroker :: client_from_url ( broker_url) . await ?;
89
+ let db = Self :: client_from_url ( broker_url) . await ?;
90
90
self . db = db;
91
91
self . connected = true ;
92
92
Ok ( ( ) )
@@ -115,7 +115,7 @@ impl Broker for SurrealDBBroker {
115
115
}
116
116
117
117
let config = self . config . clone ( ) . unwrap_or_default ( ) ;
118
- let priority = publish_options. priority . unwrap_or ( 5 ) as i64 ;
118
+ let priority = i64 :: from ( publish_options. priority . unwrap_or ( 5 ) ) ;
119
119
if !( 1 ..=5 ) . contains ( & priority) {
120
120
return Err ( BroccoliError :: Broker (
121
121
"Priority must be between 1 and 5" . to_string ( ) ,
@@ -136,7 +136,7 @@ impl Broker for SurrealDBBroker {
136
136
for msg in messages {
137
137
// 1: insert actual message //
138
138
let inserted =
139
- utils:: add_message ( & db, queue_name, & msg, "Could not publish (add msg)" ) . await ?;
139
+ utils:: add_message ( & db, queue_name, msg, "Could not publish (add msg)" ) . await ?;
140
140
published. push ( inserted) ;
141
141
142
142
// 2: add to queue //
@@ -160,7 +160,7 @@ impl Broker for SurrealDBBroker {
160
160
when,
161
161
"Could not publish scheduled (enqueue)" ,
162
162
)
163
- . await ?
163
+ . await ?;
164
164
} else if let Some ( when) = delay {
165
165
utils:: add_to_queue_delayed (
166
166
& db,
@@ -170,7 +170,7 @@ impl Broker for SurrealDBBroker {
170
170
when,
171
171
"Could not publish delayed (enqueue)" ,
172
172
)
173
- . await ?
173
+ . await ?;
174
174
}
175
175
}
176
176
}
@@ -254,7 +254,7 @@ impl Broker for SurrealDBBroker {
254
254
options : Option < ConsumeOptions > ,
255
255
) -> Result < InternalBrokerMessage , BroccoliError > {
256
256
// first of all, we try to consume without blocking, and return if we have messages
257
- let resp = Self :: try_consume ( & self , queue_name, options) . await ?;
257
+ let resp = Self :: try_consume ( self , queue_name, options) . await ?;
258
258
if let Some ( message) = resp {
259
259
return Ok ( message) ;
260
260
}
@@ -266,11 +266,11 @@ impl Broker for SurrealDBBroker {
266
266
. select ( queue_table)
267
267
. range (
268
268
vec ! [ Value :: default ( ) , Value :: default ( ) ] // note default is 'None'
269
- ..vec ! [ Value :: from_str( "time::now()" ) . unwrap_or ( Value :: default ( ) ) , Value :: default ( ) ] ,
269
+ ..vec ! [ Value :: from_str( "time::now()" ) . unwrap_or_default ( ) , Value :: default ( ) ] ,
270
270
) // should notify when future becomes present
271
271
. live ( )
272
272
. await
273
- . map_err ( |err| BroccoliError :: Broker ( format ! ( "Could not consume: {:?}" , err ) ) ) ?;
273
+ . map_err ( |err| BroccoliError :: Broker ( format ! ( "Could not consume: {err :?}" ) ) ) ?;
274
274
let mut queued_message: Result < InternalSurrealDBBrokerQueuedMessageRecord , BroccoliError > =
275
275
Err ( BroccoliError :: NotImplemented ) ;
276
276
while let Some ( notification) = futures:: StreamExt :: next ( & mut stream) . await {
@@ -287,8 +287,7 @@ impl Broker for SurrealDBBroker {
287
287
}
288
288
}
289
289
Err ( error) => Some ( Err ( BroccoliError :: Broker ( format ! (
290
- "Could not consume::'{}' {}" ,
291
- queue_name, error
290
+ "Could not consume::'{queue_name}' {error}"
292
291
) ) ) ) ,
293
292
} ;
294
293
if let Some ( message) = payload {
@@ -375,13 +374,11 @@ impl Broker for SurrealDBBroker {
375
374
>= self
376
375
. config
377
376
. as_ref ( )
378
- . map ( |config| config. retry_attempts . unwrap_or ( 3 ) )
379
- . unwrap_or ( 3 ) )
377
+ . map_or ( 3 , |config| config. retry_attempts . unwrap_or ( 3 ) ) )
380
378
|| !self
381
379
. config
382
380
. as_ref ( )
383
- . map ( |config| config. retry_failed . unwrap_or ( true ) )
384
- . unwrap_or ( true )
381
+ . map_or ( true , |config| config. retry_failed . unwrap_or ( true ) )
385
382
{
386
383
let msg = utils:: get_message (
387
384
& db,
@@ -411,8 +408,7 @@ impl Broker for SurrealDBBroker {
411
408
if self
412
409
. config
413
410
. as_ref ( )
414
- . map ( |config| config. retry_failed . unwrap_or ( true ) )
415
- . unwrap_or ( true )
411
+ . map_or ( true , |config| config. retry_failed . unwrap_or ( true ) )
416
412
{
417
413
//// 4: if retry is configured, we increase attempts ////
418
414
let mut message = message;
@@ -429,7 +425,7 @@ impl Broker for SurrealDBBroker {
429
425
priority,
430
426
"Could not reject (reenqueue)" ,
431
427
)
432
- . await ?
428
+ . await ?;
433
429
}
434
430
435
431
Ok ( ( ) )
@@ -467,8 +463,7 @@ impl Broker for SurrealDBBroker {
467
463
. await
468
464
}
469
465
None => Err ( BroccoliError :: Broker ( format ! (
470
- "Could not cancel (task_id not found):{}:{}" ,
471
- queue_name, task_id
466
+ "Could not cancel (task_id not found):{queue_name}:{task_id}"
472
467
) ) ) ,
473
468
}
474
469
}
0 commit comments