Documentation ¶
Index ¶
- Constants
- type CleanUpOption
- type CleanUpOptions
- type ExecutionResult
- type ExecutionResultSlice
- type Option
- type Options
- type TimeKeeper
- func (timeKeeper *TimeKeeper) CountAllRuns(ctx context.Context) (int64, error)
- func (timeKeeper *TimeKeeper) CountTasks(ctx context.Context) (int64, error)
- func (timeKeeper *TimeKeeper) GetAllRuns(ctx context.Context, offset, limit int64) ([]ExecutionResult, error)
- func (timeKeeper *TimeKeeper) GetLastRunOfAllTasks(ctx context.Context) ([]ExecutionResult, error)
- func (timeKeeper *TimeKeeper) GetLastRunOfTask(ctx context.Context, name string) (ExecutionResult, error)
- func (timeKeeper *TimeKeeper) Stop(ctx context.Context)
- func (timeKeeper *TimeKeeper) WrapCronTask(taskFunc crontask.TaskFunc) crontask.TaskFunc
Constants ¶
const ( // DefaultRedisExecListName is the default redis key for the list used // to track all executions of tasks managed by the time keeper. DefaultRedisExecListName = "timekeeper.executions.list" // DefaultRedisLastExecName is the default redis key for the set used // to track the latest execution of tasks managed by the time keeper. DefaultRedisLastExecName = "timekeeper.executions.aggregation" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CleanUpOption ¶
type CleanUpOption func(*CleanUpOptions)
CleanUpOption represents an option for a clean up task.
func CleanUpTaskName ¶
func CleanUpTaskName(taskName string) CleanUpOption
CleanUpTaskName sets the name of the cleanup task. The default is "timekeeper.cleanup".
func CleanUpTasksTimeOut ¶
func CleanUpTasksTimeOut(tasksTimeOut time.Duration) CleanUpOption
CleanUpTasksTimeOut sets the timeout after which tasks are cleaned up. The default is 30 days.
type CleanUpOptions ¶
CleanUpOptions bundles all available configuration properties for a time keeper clean up task.
type ExecutionResult ¶
type ExecutionResult struct { Name string LastExecution time.Time NextExecution time.Time LastDuration time.Duration Error error }
ExecutionResult describes a single recorded run of a task.
func (ExecutionResult) MarshalBinary ¶
func (p ExecutionResult) MarshalBinary() ([]byte, error)
MarshalBinary marshalls the ExecutionResult in JSON.
func (*ExecutionResult) UnmarshalBinary ¶
func (p *ExecutionResult) UnmarshalBinary(data []byte) error
UnmarshalBinary unmarshalls an ExecutionResult from JSON.
type ExecutionResultSlice ¶
type ExecutionResultSlice []ExecutionResult
ExecutionResultSlice implements sort.Interface based on the Name field.
func (ExecutionResultSlice) Len ¶
func (a ExecutionResultSlice) Len() int
func (ExecutionResultSlice) Less ¶
func (a ExecutionResultSlice) Less(i, j int) bool
func (ExecutionResultSlice) Swap ¶
func (a ExecutionResultSlice) Swap(i, j int)
type Option ¶
type Option func(*Options)
Option represents an option for a time keeper.
func CleanUpTask ¶
func CleanUpTask(client *redis.Client, setters ...CleanUpOption) Option
CleanUpTask enables the clean up task, which discards old executions. The default is nil.
func KeepLastTask ¶
KeepLastTask enables or disables the keeping of a set of the latest execution of tasks managed by the time keeper. The default is true.
func KeepTaskList ¶
KeepTaskList enables or disables the keeping of a list of all executions of tasks managed by the time keeper. The default is true.
func RedisExecListName ¶
RedisExecListName sets redis key for the list used to track all executions of tasks managed by the time keeper. The default is timekeeper.DefaultRedisExecListName.
func RedisLastExecName ¶
RedisLastExecName sets redis key for the set used to track the latest execution of tasks managed by the time keeper. The default is timekeeper.DefaultRedisLastExecName.
type Options ¶
type Options struct { RedisExecListName string RedisLastExecName string KeepTaskList bool KeepLastTask bool CleanUpTask *CleanUpOptions }
Options bundles all available configuration properties for a time keeper.
type TimeKeeper ¶
type TimeKeeper struct {
// contains filtered or unexported fields
}
TimeKeeper is a wrapper creator, used to track data about executed SynchronizedCronTasks in Redis.
It supports graceful shutdowns via its Stop() function.
func NewTimeKeeper ¶
func NewTimeKeeper(client *redis.Client, setters ...Option) (*TimeKeeper, error)
NewTimeKeeper creates a new TimeKeeper instance.
func NewTimeKeeperWithOptions ¶
func NewTimeKeeperWithOptions(client *redis.Client, options *Options) (*TimeKeeper, error)
NewTimeKeeperWithOptions creates a new TimeKeeper instance.
func (*TimeKeeper) CountAllRuns ¶
func (timeKeeper *TimeKeeper) CountAllRuns(ctx context.Context) (int64, error)
CountAllRuns returns the total amount of task executions recorded by the time keeper, and not yet cleaned up. Possible errors are related to redis connection problems.
func (*TimeKeeper) CountTasks ¶
func (timeKeeper *TimeKeeper) CountTasks(ctx context.Context) (int64, error)
CountTasks returns the amount of individual tasks recorded by the time keeper. This implies that tasks which have not yet run are not counted in. Possible errors are related to redis connection problems.
func (*TimeKeeper) GetAllRuns ¶
func (timeKeeper *TimeKeeper) GetAllRuns(ctx context.Context, offset, limit int64) ([]ExecutionResult, error)
GetAllRuns returns all tasks executions recorded by the time keeper, and not yet cleaned up. Possible errors are related to redis connection problems.
func (*TimeKeeper) GetLastRunOfAllTasks ¶
func (timeKeeper *TimeKeeper) GetLastRunOfAllTasks(ctx context.Context) ([]ExecutionResult, error)
GetLastRunOfAllTasks returns the latest execution result of all tasks recorded by the time keeper. This implies that tasks which have not yet run are not returned. Possible errors are related to redis connection problems.
func (*TimeKeeper) GetLastRunOfTask ¶
func (timeKeeper *TimeKeeper) GetLastRunOfTask(ctx context.Context, name string) (ExecutionResult, error)
GetLastRunOfTask returns the latest execution of a given task name. If the task has not been run yet, an error is returned. Possible errors are related to redis connection problems.
func (*TimeKeeper) Stop ¶
func (timeKeeper *TimeKeeper) Stop(ctx context.Context)
Stop gracefully stops the time keeper, while also freeing some of its underlying resources. This has no practical implications, other than inevitably stopping the internal cleanup task, which periodically removes timed out task executions.
func (*TimeKeeper) WrapCronTask ¶
func (timeKeeper *TimeKeeper) WrapCronTask(taskFunc crontask.TaskFunc) crontask.TaskFunc
WrapCronTask registers a TaskFunc to be recorded via this time keeper. Actual tracking is done via the task, which is provided as part of the wrapped function.