task

package
v0.9.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WrapTimeout

func WrapTimeout(t Task, noLog bool) error

WrapTimeout wraps the `Run` interface method with a timeout-dependent context.

Types

type DailyTask

type DailyTask struct {
	TimeOfDay string
	Priority  uint
	TTL       time.Duration
	SkipStart bool
	RunFunc   func(context.Context) error
}

DailyTask is a Task that is run every day.

func (DailyTask) GetPriority

func (d DailyTask) GetPriority() uint

GetPriority returns the task priority.

func (DailyTask) GetRate

func (d DailyTask) GetRate() interface{}

GetRate returns the repeat frequency for the task.

func (DailyTask) GetTTL

func (d DailyTask) GetTTL() time.Duration

GetTTL returns the maximum duration of the task. This parameter is to prevent the task from running too long if it hangs.

func (DailyTask) Run

func (d DailyTask) Run(ctx context.Context) error

Run wraps the internal RunFunc field. This method runs it and returns the result.

func (DailyTask) SkipStartup

func (d DailyTask) SkipStartup() bool

SkipStartup returns whether or not the task should be skipped during the initial startup phase.

type MinuteTask

type MinuteTask struct {
	Rate      uint64
	Priority  uint
	TTL       time.Duration
	SkipStart bool
	RunFunc   func(context.Context) error
}

MinuteTask is a Task that is run every n minutes where Rate defines how often the task is run.

func (MinuteTask) GetPriority

func (m MinuteTask) GetPriority() uint

GetPriority returns the task priority.

func (MinuteTask) GetRate

func (m MinuteTask) GetRate() interface{}

GetRate returns the repeat frequency for the task.

func (MinuteTask) GetTTL

func (m MinuteTask) GetTTL() time.Duration

GetTTL returns the maximum duration of the task. This parameter is to prevent the task from running too long if it hangs.

func (MinuteTask) Run

func (m MinuteTask) Run(ctx context.Context) error

Run wraps the internal RunFunc field. This method runs it and returns the result.

func (MinuteTask) SkipStartup

func (m MinuteTask) SkipStartup() bool

SkipStartup returns whether or not the task should be skipped during the initial startup phase.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner is the main background task runner in this package.

func NewRunner

func NewRunner() (*Runner, error)

NewRunner initializes a new Runner struct.

func (*Runner) AddTask

func (r *Runner) AddTask(task Task) error

AddTask adds the task to the runner and schedules it.

func (*Runner) Start

func (r *Runner) Start() error

Start runs all tasks in descending order of priority (where 0 is the highest priority) or by insertion order if two tasks have the same priority. Then it starts a background thread which will run all tasks every day at the specified time.

func (*Runner) Stop

func (r *Runner) Stop()

Stop stops the background thread.

type Task

type Task interface {
	Run(context.Context) error
	GetPriority() uint
	GetRate() interface{}
	GetTTL() time.Duration
	SkipStartup() bool
}

Task interface declares the methods that a Task subtype should implement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL