@ -114,41 +114,71 @@ func (q *ByteFIFOQueue) Run(atShutdown, atTerminate func(context.Context, func()
}
func ( q * ByteFIFOQueue ) readToChan ( ) {
// handle quick cancels
select {
case <- q . closed :
// tell the pool to shutdown.
q . cancel ( )
return
default :
}
backOffTime := time . Millisecond * 100
maxBackOffTime := time . Second * 3
for {
success , resetBackoff := q . doPop ( )
if resetBackoff {
backOffTime = 100 * time . Millisecond
}
if success {
select {
case <- q . closed :
// tell the pool to shutdown.
q . cancel ( )
return
default :
}
} else {
select {
case <- q . closed :
// tell the pool to shutdown.
q . cancel ( )
return
case <- time . After ( backOffTime ) :
}
backOffTime += backOffTime / 2
if backOffTime > maxBackOffTime {
backOffTime = maxBackOffTime
}
}
}
}
func ( q * ByteFIFOQueue ) doPop ( ) ( success , resetBackoff bool ) {
q . lock . Lock ( )
defer q . lock . Unlock ( )
bs , err := q . byteFIFO . Pop ( )
if err != nil {
q . lock . Unlock ( )
log . Error ( "%s: %s Error on Pop: %v" , q . typ , q . name , err )
time . Sleep ( time . Millisecond * 100 )
continue
return
}
if len ( bs ) == 0 {
q . lock . Unlock ( )
time . Sleep ( time . Millisecond * 100 )
continue
return
}
resetBackoff = true
data , err := unmarshalAs ( bs , q . exemplar )
if err != nil {
log . Error ( "%s: %s Failed to unmarshal with error: %v" , q . typ , q . name , err )
q . lock . Unlock ( )
time . Sleep ( time . Millisecond * 100 )
continue
return
}
log . Trace ( "%s %s: Task found: %#v" , q . typ , q . name , data )
q . WorkerPool . Push ( data )
q . lock . Unlock ( )
}
}
success = true
return
}
// Shutdown processing from this queue