Documentation
¶
Overview ¶
Package task provides an interface to schedule background recurring tasks
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Manager *manager
Manager is the global single task manager instance
Functions ¶
func Init ¶
func Init(repo repository.Repository) error
Init intializes the global task manager instance
Types ¶
type Stat ¶
type Stat struct {
TaskUID string
Name string
Status Status
NextRun time.Time
LastRun time.Time
Interval time.Duration
}
Stat contains the information about a current running or scheduled task
type Task ¶
type Task interface {
// UID is an unique identifier for a check
// History is kept by linking the UID's of tasks
// Changing the UID will make you lose all the task history
// Changing the frontend name can be done with the Name() function
UID() string
// Name is an user friendly task name
// You can change this as much as you like
Name() string
// Interval returns the time between executions.
Interval() time.Duration
// The function that actually gets executed when it's time
// The user slice contains all users for who the task need to executed
// In reality this will either be a single user (if the user started the task from the api)
// Or it contain all users if it's a regular interval run
// It's up to the function to decide how to handle it
// If the returned task result does not contain one of the users that was given as argument
// then the task result is not saved for that user
Func() func(context.Context, []model.User) []TaskResult
Ctx() context.Context
}
Task is the interface to which a task should adhere to You can manually implement all methods or make use of the `NewTask` function which will automatically add some logging
func NewTask ¶
func NewTask(uid, name string, interval time.Duration, fn func(context.Context, []model.User) []TaskResult, ctx ...context.Context) Task
NewTask creates a new task It supports an optional context, if none is given the background context is used Logs (info level) when a task starts and ends Logs (error level) any error that occurs during the task execution
Click to show internal directories.
Click to hide internal directories.