forked from forgejo/forgejo
Pause queues (#15928)
* Start adding mechanism to return unhandled data Signed-off-by: Andrew Thornton <art27@cantab.net> * Create pushback interface Signed-off-by: Andrew Thornton <art27@cantab.net> * Add Pausable interface to WorkerPool and Manager Signed-off-by: Andrew Thornton <art27@cantab.net> * Implement Pausable and PushBack for the bytefifos Signed-off-by: Andrew Thornton <art27@cantab.net> * Implement Pausable and Pushback for ChannelQueues and ChannelUniqueQueues Signed-off-by: Andrew Thornton <art27@cantab.net> * Wire in UI for pausing Signed-off-by: Andrew Thornton <art27@cantab.net> * add testcases and fix a few issues Signed-off-by: Andrew Thornton <art27@cantab.net> * fix build Signed-off-by: Andrew Thornton <art27@cantab.net> * prevent "race" in the test Signed-off-by: Andrew Thornton <art27@cantab.net> * fix jsoniter mismerge Signed-off-by: Andrew Thornton <art27@cantab.net> * fix conflicts Signed-off-by: Andrew Thornton <art27@cantab.net> * fix format Signed-off-by: Andrew Thornton <art27@cantab.net> * Add warnings for no worker configurations and prevent data-loss with redis/levelqueue Signed-off-by: Andrew Thornton <art27@cantab.net> * Use StopTimer Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
27ee01e1e8
commit
a82fd98d53
34 changed files with 1389 additions and 122 deletions
|
@ -54,6 +54,18 @@ type Flushable interface {
|
|||
IsEmpty() bool
|
||||
}
|
||||
|
||||
// Pausable represents a pool or queue that is Pausable
|
||||
type Pausable interface {
|
||||
// IsPaused will return if the pool or queue is paused
|
||||
IsPaused() bool
|
||||
// Pause will pause the pool or queue
|
||||
Pause()
|
||||
// Resume will resume the pool or queue
|
||||
Resume()
|
||||
// IsPausedIsResumed will return a bool indicating if the pool or queue is paused and a channel that will be closed when it is resumed
|
||||
IsPausedIsResumed() (paused, resumed <-chan struct{})
|
||||
}
|
||||
|
||||
// ManagedPool is a simple interface to get certain details from a worker pool
|
||||
type ManagedPool interface {
|
||||
// AddWorkers adds a number of worker as group to the pool with the provided timeout. A CancelFunc is provided to cancel the group
|
||||
|
@ -192,6 +204,14 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
|
|||
wg.Done()
|
||||
continue
|
||||
}
|
||||
if pausable, ok := mq.Managed.(Pausable); ok {
|
||||
// no point flushing paused queues
|
||||
if pausable.IsPaused() {
|
||||
wg.Done()
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
allEmpty = false
|
||||
if flushable, ok := mq.Managed.(Flushable); ok {
|
||||
log.Debug("Flushing (flushable) queue: %s", mq.Name)
|
||||
|
@ -215,7 +235,7 @@ func (m *Manager) FlushAll(baseCtx context.Context, timeout time.Duration) error
|
|||
log.Debug("All queues are empty")
|
||||
break
|
||||
}
|
||||
// Ensure there are always at least 100ms between loops but not more if we've actually been doing some flushign
|
||||
// Ensure there are always at least 100ms between loops but not more if we've actually been doing some flushing
|
||||
// but don't delay cancellation here.
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
|
@ -298,6 +318,12 @@ func (q *ManagedQueue) AddWorkers(number int, timeout time.Duration) context.Can
|
|||
return nil
|
||||
}
|
||||
|
||||
// Flushable returns true if the queue is flushable
|
||||
func (q *ManagedQueue) Flushable() bool {
|
||||
_, ok := q.Managed.(Flushable)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Flush flushes the queue with a timeout
|
||||
func (q *ManagedQueue) Flush(timeout time.Duration) error {
|
||||
if flushable, ok := q.Managed.(Flushable); ok {
|
||||
|
@ -315,6 +341,34 @@ func (q *ManagedQueue) IsEmpty() bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// Pausable returns whether the queue is Pausable
|
||||
func (q *ManagedQueue) Pausable() bool {
|
||||
_, ok := q.Managed.(Pausable)
|
||||
return ok
|
||||
}
|
||||
|
||||
// Pause pauses the queue
|
||||
func (q *ManagedQueue) Pause() {
|
||||
if pausable, ok := q.Managed.(Pausable); ok {
|
||||
pausable.Pause()
|
||||
}
|
||||
}
|
||||
|
||||
// IsPaused reveals if the queue is paused
|
||||
func (q *ManagedQueue) IsPaused() bool {
|
||||
if pausable, ok := q.Managed.(Pausable); ok {
|
||||
return pausable.IsPaused()
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Resume resumes the queue
|
||||
func (q *ManagedQueue) Resume() {
|
||||
if pausable, ok := q.Managed.(Pausable); ok {
|
||||
pausable.Resume()
|
||||
}
|
||||
}
|
||||
|
||||
// NumberOfWorkers returns the number of workers in the queue
|
||||
func (q *ManagedQueue) NumberOfWorkers() int {
|
||||
if pool, ok := q.Managed.(ManagedPool); ok {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue