mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-23 10:13:32 +02:00
fix: make local queue PopItem can be notified (#39011)
This commit is contained in:
@@ -25,35 +25,40 @@ type baseLevelQueuePushPoper interface {
|
||||
}
|
||||
|
||||
type baseLevelQueueCommonImpl struct {
|
||||
*baseQueueNotifiable
|
||||
length int
|
||||
internalFunc func() baseLevelQueuePushPoper
|
||||
mu *sync.Mutex
|
||||
muCommon *sync.Mutex
|
||||
}
|
||||
|
||||
func (q *baseLevelQueueCommonImpl) PushItem(ctx context.Context, data []byte) error {
|
||||
return backoffErr(ctx, backoffBegin, backoffUpper, time.After(pushBlockTime), func() (retry bool, err error) {
|
||||
if q.mu != nil {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
_, err := backoffCall(ctx, backoffOptionsDefault(noNotifyChan, time.After(pushBlockTime)), func() (retry bool, ret any, err error) {
|
||||
if q.muCommon != nil {
|
||||
q.muCommon.Lock()
|
||||
defer q.muCommon.Unlock()
|
||||
}
|
||||
|
||||
cnt := int(q.internalFunc().Len())
|
||||
if cnt >= q.length {
|
||||
return true, nil
|
||||
return true, nil, nil
|
||||
}
|
||||
retry, err = false, q.internalFunc().RPush(data)
|
||||
if err == levelqueue.ErrAlreadyInQueue {
|
||||
err = ErrAlreadyInQueue
|
||||
}
|
||||
return retry, err
|
||||
if err == nil {
|
||||
q.notifyPushItem()
|
||||
}
|
||||
return retry, nil, err
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (q *baseLevelQueueCommonImpl) PopItem(ctx context.Context) ([]byte, error) {
|
||||
return backoffRetErr(ctx, backoffBegin, backoffUpper, infiniteTimerC, func() (retry bool, data []byte, err error) {
|
||||
if q.mu != nil {
|
||||
q.mu.Lock()
|
||||
defer q.mu.Unlock()
|
||||
return backoffCall(ctx, backoffOptionsDefault(q.notifySignal, infiniteTimerC), func() (retry bool, data []byte, err error) {
|
||||
if q.muCommon != nil {
|
||||
q.muCommon.Lock()
|
||||
defer q.muCommon.Unlock()
|
||||
}
|
||||
|
||||
data, err = q.internalFunc().LPop()
|
||||
@@ -68,7 +73,7 @@ func (q *baseLevelQueueCommonImpl) PopItem(ctx context.Context) ([]byte, error)
|
||||
}
|
||||
|
||||
func baseLevelQueueCommon(cfg *BaseConfig, mu *sync.Mutex, internalFunc func() baseLevelQueuePushPoper) *baseLevelQueueCommonImpl {
|
||||
return &baseLevelQueueCommonImpl{length: cfg.Length, mu: mu, internalFunc: internalFunc}
|
||||
return &baseLevelQueueCommonImpl{length: cfg.Length, muCommon: mu, internalFunc: internalFunc, baseQueueNotifiable: newBaseQueueNotifiable()}
|
||||
}
|
||||
|
||||
func prepareLevelDB(cfg *BaseConfig) (conn string, db *leveldb.DB, err error) {
|
||||
|
||||
Reference in New Issue
Block a user