更新
This commit is contained in:
@@ -27,18 +27,19 @@ import (
|
|||||||
|
|
||||||
// 单次的任务队列
|
// 单次的任务队列
|
||||||
type Once struct {
|
type Once struct {
|
||||||
ctx context.Context // ctx
|
ctx context.Context // ctx
|
||||||
cancel context.CancelFunc // cancel
|
cancel context.CancelFunc // cancel
|
||||||
logger logger.Logger // 日志
|
logger logger.Logger // 日志
|
||||||
zsetKey string // 任务列表 有序集合
|
zsetKey string // 任务列表 有序集合
|
||||||
listKey string //
|
listKey string // 列表
|
||||||
redis redis.UniversalClient // Redis
|
globalLockPrefix string // 全局锁的前缀
|
||||||
worker Callback // 回调
|
redis redis.UniversalClient // Redis
|
||||||
keyPrefix string //
|
worker Callback // 回调
|
||||||
priority *priority.Priority // 全局优先级
|
keyPrefix string //
|
||||||
usePriority bool //
|
priority *priority.Priority // 全局优先级
|
||||||
batchSize int // 每批大小
|
usePriority bool //
|
||||||
wg sync.WaitGroup //
|
batchSize int // 每批大小
|
||||||
|
wg sync.WaitGroup //
|
||||||
|
|
||||||
stopChan chan struct{} //
|
stopChan chan struct{} //
|
||||||
instanceId string // 实例ID
|
instanceId string // 实例ID
|
||||||
@@ -92,22 +93,23 @@ func InitOnce(ctx context.Context, re redis.UniversalClient, keyPrefix string, c
|
|||||||
u, _ := uuid.NewV7()
|
u, _ := uuid.NewV7()
|
||||||
|
|
||||||
wo := &Once{
|
wo := &Once{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
logger: op.logger,
|
logger: op.logger,
|
||||||
zsetKey: "timer:once_zsetkey" + keyPrefix,
|
zsetKey: "timer:once_zsetkey" + keyPrefix,
|
||||||
listKey: "timer:once_listkey" + keyPrefix,
|
listKey: "timer:once_listkey" + keyPrefix,
|
||||||
executeInfoKey: "timer:once_executeInfoKey" + keyPrefix,
|
executeInfoKey: "timer:once_executeInfoKey" + keyPrefix,
|
||||||
usePriority: op.usePriority,
|
globalLockPrefix: "timer:once_globalLockPrefix" + keyPrefix,
|
||||||
redis: re,
|
usePriority: op.usePriority,
|
||||||
worker: call,
|
redis: re,
|
||||||
keyPrefix: keyPrefix,
|
worker: call,
|
||||||
batchSize: op.batchSize,
|
keyPrefix: keyPrefix,
|
||||||
stopChan: make(chan struct{}),
|
batchSize: op.batchSize,
|
||||||
instanceId: u.String(),
|
stopChan: make(chan struct{}),
|
||||||
keySeparator: "[:]",
|
instanceId: u.String(),
|
||||||
timeout: op.timeout,
|
keySeparator: "[:]",
|
||||||
maxRetryCount: op.maxRetryCount,
|
timeout: op.timeout,
|
||||||
|
maxRetryCount: op.maxRetryCount,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 初始化优先级
|
// 初始化优先级
|
||||||
@@ -434,7 +436,7 @@ func (l *Once) processTask(key string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 这里加一个全局锁
|
// 这里加一个全局锁
|
||||||
lock, err := lockx.NewGlobalLock(ctx, l.redis, key)
|
lock, err := lockx.NewGlobalLock(ctx, l.redis, l.globalLockPrefix+key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.logger.Errorf(ctx, "processTask timer:获取锁失败:%s", taskId)
|
l.logger.Errorf(ctx, "processTask timer:获取锁失败:%s", taskId)
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user