diff --git a/const.go b/const.go index 7b125d6..4031162 100644 --- a/const.go +++ b/const.go @@ -1,5 +1,5 @@ package gojobs -const Version = "1.0.70" +const Version = "1.0.71" const SpecifyIpNull = "0.0.0.0" diff --git a/jobs_gorm_lock_id.go b/jobs_gorm_lock_id.go new file mode 100644 index 0000000..380dd74 --- /dev/null +++ b/jobs_gorm_lock_id.go @@ -0,0 +1,23 @@ +package gojobs + +import ( + "context" + "fmt" + "go.dtapp.net/gojobs/jobs_gorm_model" + "time" +) + +// LockId 上锁 +func (j *JobsGorm) LockId(ctx context.Context, info jobs_gorm_model.Task) (string, error) { + return j.lockClient.Lock(ctx, fmt.Sprintf("%s%s%v%s%v", j.config.lockKeyPrefix, j.config.lockKeySeparator, info.Type, j.config.lockKeySeparator, info.Id), fmt.Sprintf("已在%s@%s机器上锁成功", j.config.insideIp, j.config.outsideIp), time.Duration(info.Frequency)*3*time.Second) +} + +// UnlockId Lock 解锁 +func (j *JobsGorm) UnlockId(ctx context.Context, info jobs_gorm_model.Task) error { + return j.lockClient.Unlock(ctx, fmt.Sprintf("%s%s%v%s%v", j.config.lockKeyPrefix, j.config.lockKeySeparator, info.Type, j.config.lockKeySeparator, info.Id)) +} + +// LockForeverId 永远上锁 +func (j *JobsGorm) LockForeverId(ctx context.Context, info jobs_gorm_model.Task) (string, error) { + return j.lockClient.LockForever(ctx, fmt.Sprintf("%s%s%v%s%v", j.config.lockKeyPrefix, j.config.lockKeySeparator, info.Type, j.config.lockKeySeparator, info.Id), fmt.Sprintf("已在%s@%s机器永远上锁成功", j.config.insideIp, j.config.outsideIp)) +}