diff options
author | zeripath <art27@cantab.net> | 2020-02-02 23:19:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-02 23:19:58 +0000 |
commit | 2c903383b5154795b90e4b4ed8eaadc6fac17a13 (patch) | |
tree | d5ca361d9597e027ad92f1e02a841be1d266b554 /modules/queue/unique_queue.go | |
parent | b4914249ee389a733e7dcfd2df20708ab3215827 (diff) | |
download | gitea-2c903383b5154795b90e4b4ed8eaadc6fac17a13.tar.gz gitea-2c903383b5154795b90e4b4ed8eaadc6fac17a13.zip |
Add Unique Queue infrastructure and move TestPullRequests to this (#9856)
* Upgrade levelqueue to version 0.2.0
This adds functionality for Unique Queues
* Add UniqueQueue interface and functions to create them
* Add UniqueQueue implementations
* Move TestPullRequests over to use UniqueQueue
* Reduce code duplication
* Add bytefifos
* Ensure invalid types are logged
* Fix close race in PersistableChannelQueue Shutdown
Diffstat (limited to 'modules/queue/unique_queue.go')
-rw-r--r-- | modules/queue/unique_queue.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/queue/unique_queue.go b/modules/queue/unique_queue.go new file mode 100644 index 0000000000..87e0594ecf --- /dev/null +++ b/modules/queue/unique_queue.go @@ -0,0 +1,29 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package queue + +import ( + "fmt" +) + +// UniqueQueue defines a queue which guarantees only one instance of same +// data is in the queue. Instances with same identity will be +// discarded if there is already one in the line. +// +// This queue is particularly useful for preventing duplicated task +// of same purpose - please note that this does not guarantee that a particular +// task cannot be processed twice or more at the same time. Uniqueness is +// only guaranteed whilst the task is waiting in the queue. +// +// Users of this queue should be careful to push only the identifier of the +// data +type UniqueQueue interface { + Queue + PushFunc(Data, func() error) error + Has(Data) (bool, error) +} + +// ErrAlreadyInQueue is returned when trying to push data to the queue that is already in the queue +var ErrAlreadyInQueue = fmt.Errorf("already in queue") |