Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SingletonTaskConfig ¶
type SingletonTaskConfig struct {
// TaskName is the unique name for this task (used as lock name).
TaskName string
// LockTimeout is how long the lock is held before expiring.
// Should be longer than the expected task duration.
// Default: 60 seconds
LockTimeout time.Duration
}
SingletonTaskConfig configures a singleton task.
func DefaultSingletonConfig ¶
func DefaultSingletonConfig(taskName string) SingletonTaskConfig
DefaultSingletonConfig returns the default configuration.
type SingletonTaskRunner ¶
type SingletonTaskRunner struct {
// contains filtered or unexported fields
}
SingletonTaskRunner runs tasks as a singleton across the cluster. Only one worker can run the task at a time using system locks.
func NewSingletonTaskRunner ¶
func NewSingletonTaskRunner(lockManager SystemLockManager, workerID string, config SingletonTaskConfig) *SingletonTaskRunner
NewSingletonTaskRunner creates a new singleton task runner.
func (*SingletonTaskRunner) TryRun ¶
func (r *SingletonTaskRunner) TryRun(ctx context.Context, task func(context.Context) error) (bool, error)
TryRun attempts to acquire the lock and run the task. Returns (true, nil) if the task was executed successfully. Returns (false, nil) if the lock was not acquired (another worker is running). Returns (false, error) if there was an error acquiring lock or running task.
type SystemLockManager ¶
type SystemLockManager interface {
TryAcquireSystemLock(ctx context.Context, lockName, workerID string, timeoutSec int) (bool, error)
ReleaseSystemLock(ctx context.Context, lockName, workerID string) error
}
SystemLockManager is the interface for system lock operations. This is a subset of storage.Storage that SingletonTaskRunner needs.