You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gojobs/task_lock.go

74 lines
1.8 KiB

2 years ago
package gojobs
2 years ago
import (
"context"
"errors"
2 years ago
"go.dtapp.net/gojobs/jobs_gorm_model"
2 years ago
)
type TaskLockOperation struct {
2 years ago
client *Client // 实例
task jobs_gorm_model.Task // 任务
2 years ago
}
2 years ago
func (c *Client) NewLock(task jobs_gorm_model.Task) (*TaskLockOperation, error) {
2 years ago
if task.Id == 0 {
return nil, errors.New("任务数据不正常")
}
return &TaskLockOperation{
client: c,
2 years ago
task: task,
2 years ago
}, nil
}
2 years ago
// Lock 上锁
func (tlo *TaskLockOperation) Lock(ctx context.Context, id any) error {
_, err := tlo.client.Lock(ctx, tlo.task, id)
return err
}
// Unlock 解锁
func (tlo *TaskLockOperation) Unlock(ctx context.Context, id any) error {
return tlo.client.Unlock(ctx, tlo.task, id)
}
// LockForever 永远上锁
func (tlo *TaskLockOperation) LockForever(ctx context.Context, id any) error {
_, err := tlo.client.LockForever(ctx, tlo.task, id)
return err
}
2 years ago
// LockId 上锁
func (tlo *TaskLockOperation) LockId(ctx context.Context) error {
_, err := tlo.client.LockId(ctx, tlo.task)
return err
}
// UnlockId 解锁
func (tlo *TaskLockOperation) UnlockId(ctx context.Context) error {
return tlo.client.UnlockId(ctx, tlo.task)
}
// LockForeverId 永远上锁
func (tlo *TaskLockOperation) LockForeverId(ctx context.Context) error {
_, err := tlo.client.LockForeverId(ctx, tlo.task)
return err
}
// LockCustomId 上锁
func (tlo *TaskLockOperation) LockCustomId(ctx context.Context) error {
_, err := tlo.client.LockCustomId(ctx, tlo.task)
return err
}
// UnlockCustomId 解锁
func (tlo *TaskLockOperation) UnlockCustomId(ctx context.Context) error {
return tlo.client.UnlockCustomId(ctx, tlo.task)
}
// LockForeverCustomId 永远上锁
func (tlo *TaskLockOperation) LockForeverCustomId(ctx context.Context) error {
_, err := tlo.client.LockForeverCustomId(ctx, tlo.task)
return err
}