-
Notifications
You must be signed in to change notification settings - Fork 0
/
lock_custom_id.go
23 lines (19 loc) · 1.27 KB
/
lock_custom_id.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package gojobs
import (
"context"
"fmt"
"go.dtapp.net/gotime"
"time"
)
// LockCustomId 上锁
func (c *Client) LockCustomId(ctx context.Context, info *GormModelTask) (string, error) {
return c.lock(ctx, fmt.Sprintf("%s%s%v%s%v", c.redisConfig.lockKeyPrefix, c.redisConfig.lockKeySeparator, info.Type, c.redisConfig.lockKeySeparator, info.CustomID), fmt.Sprintf("[LockCustomId] 已在%s@%s机器上锁成功,时间:%v", c.config.systemInsideIP, c.config.systemOutsideIP, gotime.Current().Format()), time.Duration(info.Frequency)*3*time.Second)
}
// UnlockCustomId 解锁
func (c *Client) UnlockCustomId(ctx context.Context, info *GormModelTask) error {
return c.unlock(ctx, fmt.Sprintf("%s%s%v%s%v", c.redisConfig.lockKeyPrefix, c.redisConfig.lockKeySeparator, info.Type, c.redisConfig.lockKeySeparator, info.CustomID))
}
// LockForeverCustomId 永远上锁
func (c *Client) LockForeverCustomId(ctx context.Context, info *GormModelTask) (string, error) {
return c.lockForever(ctx, fmt.Sprintf("%s%s%v%s%v", c.redisConfig.lockKeyPrefix, c.redisConfig.lockKeySeparator, info.Type, c.redisConfig.lockKeySeparator, info.CustomID), fmt.Sprintf("[LockCustomId] 已在%s@%s机器永远上锁成功,时间:%v", c.config.systemInsideIP, c.config.systemOutsideIP, gotime.Current().Format()))
}