taskservice

package
v0.0.0-...-cf91c1a Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2018 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Poller

type Poller interface {
	Start() error
	Stop() error
}

Poller interface describes the behavior of a general polling service. It exposes the basic control methods.

type Runner

type Runner interface {
	RunTask(task Task) error
	CancelTask(id string) error
}

Runner interface describes the task runner behavior for controlling active tasks.

type Source

type Source interface {
	GetAllTasks() ([]Task, error)
	GetPendingTasks() ([]Task, error)
	GetCancelledTasks() ([]string, error)
}

Source interface describes task source behavior. Implementation is mainly to abstract the backend datastore and returns structs that implement the Task interface.

type Task

type Task interface {
	Run() error
	ID() string
	SetRunning() error
	SetFailed() error
	SetStopped() error
}

Task interface provides the behavior for the runner to periodically execute a synchronization job. Structs that implement this interface can be executed by this scheduling service.

type TaskPoller

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

TaskPoller struct holds all the state logic and child structures to watch a backend datastore and schedule tasks to run periodically. This implements the Poller interface.

func NewTaskPoller

func NewTaskPoller(runner Runner, source Source) (*TaskPoller, error)

NewTaskPoller returns a TaskPoller struct which implements the Poller interface. It is composed of a Runner and Source interface.

func (*TaskPoller) Start

func (t *TaskPoller) Start() error

Start implements the Start functionality of the Poller interface.

func (*TaskPoller) Stop

func (t *TaskPoller) Stop() error

Stop implements the Stop functionality of the Poller interface.

type TaskRunner

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

TaskRunner holds references to all actively scheduled tasks. This is primarily a structure to hold a map back to the schedule task threads for cleanup & monitoring.

func NewTaskRunner

func NewTaskRunner() (*TaskRunner, error)

NewTaskRunner returns a new empty TaskRunner

func (*TaskRunner) CancelTask

func (t *TaskRunner) CancelTask(id string) error

CancelTask stops a running task and removes its reference from the TaskRunner struct

func (*TaskRunner) RunTask

func (t *TaskRunner) RunTask(task Task) error

RunTask schedules a new Task to be periodically called

type TaskScheduler

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

TaskScheduler is the top-level scheduler service class This class wraps the embedded polling service to start and create new synchronizer jobs. This should probably be moved to something more "eventy" in the future but this works for now.

func NewTaskScheduler

func NewTaskScheduler(db backend.Database) (*TaskScheduler, error)

NewTaskScheduler composes all the underlying services to create the task scheduler and synchronization service.

type TaskSource

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

TaskSource implements the Source interface. This is a DB/backend specific implementation that provides implementation of the synchronization jobs to the task scheduler & runner services.

func NewTaskSource

func NewTaskSource(db backend.Database) (*TaskSource, error)

NewTaskSource composes a TaskSource object that implements the Source interface

func (*TaskSource) GetAllTasks

func (s *TaskSource) GetAllTasks() ([]Task, error)

GetAllTasks provides Synchronizers that implement the Task interface. This is primarily used to do initial scheduling on system startup.

func (*TaskSource) GetCancelledTasks

func (s *TaskSource) GetCancelledTasks() ([]string, error)

GetCancelledTasks provides Synchronizers that implement the Task interface. This is used to get all tasks in a pending state that are awaiting scheduling.

func (*TaskSource) GetPendingTasks

func (s *TaskSource) GetPendingTasks() ([]Task, error)

GetPendingTasks provides Synchronizers that implement the Task interface. This is used to get all tasks in a pending state that are awaiting scheduling.

Jump to

Keyboard shortcuts

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