1、波段触发修改
This commit is contained in:
@ -46,9 +46,9 @@ const (
|
||||
SpotTrigger = "spot_trigger_lock:%v_%s" //现货触发 {apiuserid|symbol}
|
||||
FutTrigger = "fut_trigger_lock:%v_%s" //合约触发 {apiuserid|symbol}
|
||||
|
||||
//波段现货触发{apiuserid|symbol}
|
||||
//波段现货触发{apiuserid|ordersn}
|
||||
StrategySpotTriggerLock = "strategy_spot_trigger_l:%v_%s"
|
||||
//波段合约触发{apiuserid|symbol}
|
||||
//波段合约触发{apiuserid|ordersn}
|
||||
StrategyFutTriggerLock = "strategy_fut_trigger_l:%v_%s"
|
||||
|
||||
//减仓波段合约触发 {apiuserid|symbol}
|
||||
|
||||
@ -106,6 +106,9 @@ func (rl *RedisLock) AcquireWait(ctx context.Context) (bool, error) {
|
||||
baseInterval = time.Second
|
||||
}
|
||||
|
||||
if baseInterval <= 0 {
|
||||
baseInterval = time.Millisecond * 100 // 至少 100ms
|
||||
}
|
||||
// 随机退避
|
||||
retryInterval := time.Duration(rand.Int63n(int64(baseInterval))) // 随机退避
|
||||
if retryInterval < time.Millisecond*100 {
|
||||
@ -129,6 +132,13 @@ func (rl *RedisLock) AcquireWait(ctx context.Context) (bool, error) {
|
||||
return false, ErrFailed
|
||||
}
|
||||
|
||||
func safeRandomDuration(max time.Duration) time.Duration {
|
||||
if max <= 0 {
|
||||
return 100 * time.Millisecond // fallback default
|
||||
}
|
||||
return time.Duration(rand.Int63n(int64(max)))
|
||||
}
|
||||
|
||||
// Release 释放锁
|
||||
func (rl *RedisLock) Release() (bool, error) {
|
||||
return rl.releaseCtx(context.Background())
|
||||
|
||||
Reference in New Issue
Block a user