schedule

package
Version: v2.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//Scheduled indicates that this is the invocation was due to a schedule
	Scheduled = "Scheduled"
	//Retry indicates that this is the invocation is a retry of a previously failed invocation
	Retry = "Retry"
	//Manual indicates that this is the invocation was triggered outside of a schedule
	Manual = "Manual"
)
View Source
const (
	//OffsetFromStart indicates the interval between invocations is relative to the time the application started
	OffsetFromStart intervalMode = iota

	//ActualStartTime indicates that the invocation will run at a specified time
	ActualStartTime
)
View Source
const (
	//LLComponentName is the name of the component that handles the management of scheduled tasks
	LLComponentName = instance.FrameworkPrefix + "CommandScheduledTasks"
)

Variables

This section is empty.

Functions

func NewAllowRetryErrorf

func NewAllowRetryErrorf(template string, args ...interface{}) error

NewAllowRetryErrorf creates a an AllowRetryError with the supplied message

Types

type AllowRetryError

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

AllowRetryError indicates a non-fatal problem that means retrying the task is permissible

func (*AllowRetryError) Error

func (e *AllowRetryError) Error() string

Error returns the error message

type Task

type Task struct {

	// A human-readable name for the task
	Name string
	// An optional unique ID for the task (the IoC component name for this task will be used if not specified)
	ID string
	// The name of the IoC component implementing TaskLogic that actually performs this task
	Component string
	// The maximum number of overlapping instances of the task that are allowed to run. Zero means only one instance of this task can run at a time
	MaxOverlapping int
	// If set to true, suppress warning messages being logged when a task is scheduled to run while another instance is already running
	NoWarnOnOverlap bool
	// A human-readable expression (in English) of how frequently the task should be run - see package docs
	Every string

	// If set to true, any status updates messages sent from the task to the scheduler will be logged
	LogStatusMessages bool

	// The name of a component that is interested in receiving status updates from a running task
	StatusUpdateReceiver string

	// If set to true the task will never run
	Disabled bool

	// The number of times an invocation of this task should be re-tried if the task fails with an AllowRetryError
	MaxRetries int

	// A human-readable expression (in English) of how the interval to wait between a failure and a retry (e.g. 1 minute, 20 seconds)
	// Must be set if MaxRetries > 0
	RetryInterval string
	// contains filtered or unexported fields
}

Task describes when and how frequently a scheduled task should be executed and the component that provides a method to actually perform the task

func (*Task) FullName

func (t *Task) FullName() string

FullName returns either task name + ID, just task name or just ID depending on which fields are set

type TaskInvocationSummary

type TaskInvocationSummary struct {
	TaskName        string
	TaskID          string
	StartedAt       time.Time
	InvocationCount uint64
}

TaskInvocationSummary meta-data about a task invocation

type TaskLogic

type TaskLogic interface {
	ExecuteTask(c chan TaskStatusUpdate) error
}

TaskLogic is implemented by any component that can be invoked via a scheduled task

type TaskScheduler

type TaskScheduler struct {
	State ioc.ComponentState
	// Logger used by Granitic framework components. Automatically injected.
	FrameworkLogger     logging.Logger
	FrameworkLogManager *logging.ComponentLoggerManager
	// contains filtered or unexported fields
}

TaskScheduler is the top level Granitic component for managing the scheduled invocation of tasks

func (*TaskScheduler) AllowAccess

func (ts *TaskScheduler) AllowAccess() error

AllowAccess spawns a goroutinue managing each scheduled task

func (*TaskScheduler) Container

func (ts *TaskScheduler) Container(container *ioc.ComponentContainer)

Container implements ioc.ContainerAccessor.Container

func (*TaskScheduler) PrepareToStop

func (ts *TaskScheduler) PrepareToStop()

PrepareToStop calls the same method of each of the managed Tasks

func (*TaskScheduler) ReadyToStop

func (ts *TaskScheduler) ReadyToStop() (bool, error)

ReadyToStop only returns true when each of the managed tasks report that they are ReadyToStop

func (*TaskScheduler) StartComponent

func (ts *TaskScheduler) StartComponent() error

StartComponent Finds any schedules, parses them and verifies the component they reference implements schedule.TaskLogic

func (*TaskScheduler) Stop

func (ts *TaskScheduler) Stop() error

Stop calls the same method on each of the managed tasks. Any errors returned when stopping the underlying tasks are concatenated together and returned as a single error

type TaskStatusUpdate

type TaskStatusUpdate struct {
	Message string
	Status  interface{}
}

TaskStatusUpdate allows a task to communicate back to its manager some status.

func StatusMessagef

func StatusMessagef(format string, a ...interface{}) TaskStatusUpdate

StatusMessagef creates a TaskStatusUpdate with the supplied message

type TaskStatusUpdateReceiver

type TaskStatusUpdateReceiver interface {
	Receive(summary TaskInvocationSummary, update TaskStatusUpdate)
}

TaskStatusUpdateReceiver is implemented by a component that wants to receive status updates about an invocation of a task

Jump to

Keyboard shortcuts

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