@@ -35,9 +35,9 @@ var DefaultConfiguration Configuration
35
35
// Configuration AMQP configuration settings, this settings are set using the
36
36
// envinroment varabiles.
37
37
type Configuration struct {
38
- BuriedQueueSuffix string `envconfig:"BURIED_QUEUE_SUFFIX" default:".buriedQueue"`
39
- BuriedExchangeSuffix string `envconfig:"BURIED_EXCHANGE_SUFFIX" default:".buriedExchange"`
40
- BuriedNonBlockingRetries int `envconfig:"BURIED_BLOCKING_RETRIES " default:"3 "`
38
+ BuriedQueueSuffix string `envconfig:"BURIED_QUEUE_SUFFIX" default:".buriedQueue"`
39
+ BuriedExchangeSuffix string `envconfig:"BURIED_EXCHANGE_SUFFIX" default:".buriedExchange"`
40
+ BuriedTimeout int `envconfig:"BURIED_TIMEOUT " default:"500 "`
41
41
42
42
RetriesHeader string `envconfig:"RETRIES_HEADER" default:"x-retries"`
43
43
ErrorHeader string `envconfig:"ERROR_HEADER" default:"x-error-type"`
@@ -345,41 +345,22 @@ func (q *Queue) RepublishBuried(conditions ...queue.RepublishConditionFunc) erro
345
345
346
346
defer iter .Close ()
347
347
348
- retries := 0
348
+ timeout := time .Duration (DefaultConfiguration .BuriedTimeout ) * time .Millisecond
349
+
349
350
var notComplying []* queue.Job
350
351
var errorsPublishing []* jobErr
351
352
for {
352
- j , err := iter .(* JobIter ).nextNonBlocking ( )
353
+ j , err := iter .(* JobIter ).nextWithTimeout ( timeout )
353
354
if err != nil {
354
355
return err
355
356
}
356
357
357
358
if j == nil {
358
- log .With (log.Fields {
359
- "retries" : retries ,
360
- }).Debugf ("received empty job" )
361
-
362
- // check (in non blocking mode) up to DefaultConfiguration.BuriedNonBlockingRetries
363
- // with a small delay between them just in case some job is
364
- // arriving, return if there is nothing after all the retries
365
- // (meaning: BuriedQueue is surely empty or any arriving jobs will
366
- // have to wait to the next call).
367
- if retries > DefaultConfiguration .BuriedNonBlockingRetries {
368
- log .With (log.Fields {
369
- "retries" : retries ,
370
- "max-retries" : DefaultConfiguration .BuriedNonBlockingRetries ,
371
- }).Debugf ("maximum number of retries reached" )
359
+ log .Debugf ("no more jobs in the buried queue" )
372
360
373
- break
374
- }
375
-
376
- time .Sleep (50 * time .Millisecond )
377
- retries ++
378
- continue
361
+ break
379
362
}
380
363
381
- retries = 0
382
-
383
364
if err = j .Ack (); err != nil {
384
365
return err
385
366
}
@@ -541,15 +522,15 @@ func (i *JobIter) Next() (*queue.Job, error) {
541
522
return fromDelivery (& d )
542
523
}
543
524
544
- func (i * JobIter ) nextNonBlocking ( ) (* queue.Job , error ) {
525
+ func (i * JobIter ) nextWithTimeout ( timeout time. Duration ) (* queue.Job , error ) {
545
526
select {
546
527
case d , ok := <- i .c :
547
528
if ! ok {
548
529
return nil , queue .ErrAlreadyClosed .New ()
549
530
}
550
531
551
532
return fromDelivery (& d )
552
- default :
533
+ case <- time . After ( timeout ) :
553
534
return nil , nil
554
535
}
555
536
}
0 commit comments