Documentation
¶
Index ¶
- Constants
- type SynchronizedCronTask
- func (synchronizedCronTask *SynchronizedCronTask) ExecuteNow()
- func (synchronizedCronTask *SynchronizedCronTask) MarshalJSON() ([]byte, error)
- func (synchronizedCronTask *SynchronizedCronTask) Name() string
- func (synchronizedCronTask *SynchronizedCronTask) NextTime() time.Time
- func (synchronizedCronTask *SynchronizedCronTask) Stop(ctx context.Context)
- type Task
- type TaskFunc
- type TaskOption
- func CronExpression(cronExpression string) TaskOption
- func LeadershipTimeout(leadershipTimeout time.Duration) TaskOption
- func LockHeartbeat(lockHeartbeat time.Duration) TaskOption
- func LockTimeout(lockTimeout time.Duration) TaskOption
- func Logger(logger *logrus.Logger) TaskOption
- func TaskName(name string) TaskOption
- type TaskOptions
Constants ¶
const ( // DefaultName is the default name of a synchronized cron task. DefaultName = "Default Synchronized Task" // DefaultCronExpression is the default cron expression of a // synchronized cron task. 0 * * * * * means every minute. DefaultCronExpression = "0 * * * * *" // DefaultLeadershipTimeout is the default timeout of a single // execution of a synchronized cron task. DefaultLeadershipTimeout = 30 * time.Second // DefaultLockTimeout is the default timeout for the lock of a // single execution of a synchronized cron task. DefaultLockTimeout = 5 * time.Second // DefaultLockHeartbeat is the default interval, in which an // acquired lock should be renewed (to the total of the leadership // timeout). DefaultLockHeartbeat = 1 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SynchronizedCronTask ¶
type SynchronizedCronTask struct {
// contains filtered or unexported fields
}
SynchronizedCronTask describes a task, which is identified by a cron expression and a redis client it uses to synchronize execution across running instances.
It supports graceful shutdowns via its Stop() function.
func NewSynchronizedCronTask ¶
func NewSynchronizedCronTask(client redislock.RedisClient, taskFunc TaskFunc, setters ...TaskOption) (*SynchronizedCronTask, error)
NewSynchronizedCronTask creates a new SynchronizedCronTask instance, or errors out if the provided cron expression was invalid.
func NewSynchronizedCronTaskWithOptions ¶
func NewSynchronizedCronTaskWithOptions(client redislock.RedisClient, taskFunc TaskFunc, options *TaskOptions) (*SynchronizedCronTask, error)
NewSynchronizedCronTaskWithOptions creates a new SynchronizedCronTask instance, or errors out if the provided cron expression was invalid.
func (*SynchronizedCronTask) ExecuteNow ¶
func (synchronizedCronTask *SynchronizedCronTask) ExecuteNow()
ExecuteNow forces the cron to fire immediately. Locking is still honored, so no concurrent task execution can be forced this way.
func (*SynchronizedCronTask) MarshalJSON ¶
func (synchronizedCronTask *SynchronizedCronTask) MarshalJSON() ([]byte, error)
func (*SynchronizedCronTask) Name ¶
func (synchronizedCronTask *SynchronizedCronTask) Name() string
Name returns the name of the task.
func (*SynchronizedCronTask) NextTime ¶
func (synchronizedCronTask *SynchronizedCronTask) NextTime() time.Time
NextTime returns the next time the cron task will fire.
func (*SynchronizedCronTask) Stop ¶
func (synchronizedCronTask *SynchronizedCronTask) Stop(ctx context.Context)
Stop gracefully stops the task, while also freeing most of its underlying resources.
type TaskOption ¶
type TaskOption func(*TaskOptions)
TaskOption represents an option for a synchronized cron task.
func CronExpression ¶
func CronExpression(cronExpression string) TaskOption
CronExpression sets the cron expression of the synchronized cron task. The default is crontask.DefaultCronExpression.
func LeadershipTimeout ¶
func LeadershipTimeout(leadershipTimeout time.Duration) TaskOption
LeadershipTimeout sets the timeout of a single execution of the synchronized cron task. The default is crontask.DefaultLeadershipTimeout.
func LockHeartbeat ¶
func LockHeartbeat(lockHeartbeat time.Duration) TaskOption
LockHeartbeat sets the interval, in which an acquired lock should be renewed (to the total of LeadershipTimeout). This should be smaller than the LockTimeout, otherwise the task will have no chance to ever renew the lock. The default is crontask.DefaultLockHeartbeat.
func LockTimeout ¶
func LockTimeout(lockTimeout time.Duration) TaskOption
LockTimeout sets the timeout for the lock of a single execution of the synchronized cron task. It is good practice to keep the timeout small, for fast failure detection. The default is crontask.DefaultLockTimeout.
func Logger ¶
func Logger(logger *logrus.Logger) TaskOption
Logger sets the logger of the synchronized cron task. The default is the logrus global default logger.
func TaskName ¶
func TaskName(name string) TaskOption
TaskName sets the name of the synchronized cron task. The default is crontask.DefaultName.