schedulerd

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NextCronTime

func NextCronTime(now time.Time, cronStr string) (time.Duration, error)

NextCronTime calculates how much time is between the current time and the time indidcated by the cron string

Types

type AdhocRequestExecutor

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

AdhocRequestExecutor takes new check requests from the adhoc queue and runs them

func NewAdhocRequestExecutor

func NewAdhocRequestExecutor(ctx context.Context, store store.Store, queue types.Queue, bus messaging.MessageBus, cache *EntityCache) *AdhocRequestExecutor

NewAdhocRequestExecutor returns a new AdhocRequestExecutor.

func (*AdhocRequestExecutor) Stop

func (a *AdhocRequestExecutor) Stop()

Stop calls the context cancel function to stop the AdhocRequestExecutor.

type CheckExecutor

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

CheckExecutor executes scheduled checks in the check scheduler

func NewCheckExecutor

func NewCheckExecutor(bus messaging.MessageBus, namespace string, store store.Store, cache *EntityCache) *CheckExecutor

NewCheckExecutor creates a new check executor

type CheckTimer

type CheckTimer interface {
	// C channel emits events when timer's duration has reached 0
	C() <-chan time.Time
	// SetDuration updates the interval in which timers are set
	SetDuration(string, uint)
	// Start sets up a new timer
	Start()
	// Next reset's timer using interval
	Next()
	// Stop ends the timer
	Stop()
}

A CheckTimer handles starting and stopping timers for a given check

type CheckWatcher

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

CheckWatcher manages all the check schedulers

func NewCheckWatcher

func NewCheckWatcher(ctx context.Context, msgBus messaging.MessageBus, store store.Store, pool *ringv2.Pool, cache *EntityCache) *CheckWatcher

NewCheckWatcher creates a new ScheduleManager.

func (*CheckWatcher) Start

func (c *CheckWatcher) Start() error

Start starts the CheckWatcher.

type Config

type Config struct {
	Store       store.Store
	QueueGetter types.QueueGetter
	RingPool    *ringv2.Pool
	Bus         messaging.MessageBus
}

Config configures Schedulerd.

type CronScheduler

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

IntervalScheduler schedules checks to be executed on a cron schedule.

func NewCronScheduler

func NewCronScheduler(ctx context.Context, store store.Store, bus messaging.MessageBus, check *corev2.CheckConfig, cache *EntityCache) *CronScheduler

func (*CronScheduler) Interrupt

func (s *CronScheduler) Interrupt(check *corev2.CheckConfig)

Interrupt refreshes the scheduler with a revised check config.

func (*CronScheduler) Start

func (s *CronScheduler) Start()

func (*CronScheduler) Stop

func (s *CronScheduler) Stop() error

func (*CronScheduler) Type

func (s *CronScheduler) Type() SchedulerType

type CronTimer

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

A CronTimer handles starting and stopping timers for a given check

func NewCronTimer

func NewCronTimer(name string, cronStr string) *CronTimer

NewCronTimer establishes new check timer given a name & an initial interval

func (*CronTimer) C

func (timerPtr *CronTimer) C() <-chan time.Time

C channel emits events when timer's duration has reached 0

func (*CronTimer) Next

func (timerPtr *CronTimer) Next()

Next reset's timer using interval

func (*CronTimer) SetDuration

func (timerPtr *CronTimer) SetDuration(cronStr string, interval uint)

SetDuration updates the interval in which timers are set

func (*CronTimer) Start

func (timerPtr *CronTimer) Start()

Start sets up a new timer

func (*CronTimer) Stop

func (timerPtr *CronTimer) Stop()

Stop ends the timer

type EntityCache

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

EntityCache is a cache of entities. The cache uses a watcher on entities in order to keep itself up to date. Entities can be efficiently retrieved from the cache by namespace.

func NewEntityCache

func NewEntityCache(ctx context.Context, s store.EntityStore) (*EntityCache, error)

NewEntityCache creates a new EntityCache. It retrieves all entities from the store on creation.

func (*EntityCache) GetEntities

func (e *EntityCache) GetEntities(namespace string) []EntityCacheValue

GetEntities gets all entities in a namespace.

func (*EntityCache) Watch

func (e *EntityCache) Watch(ctx context.Context) <-chan struct{}

Watch allows cache users to get notified when the cache has new values. When the context is canceled, the channel will be closed.

type EntityCacheValue

type EntityCacheValue struct {
	Entity *corev2.Entity
	Synth  interface{}
}

EntityCacheValue contains an entity, and its synthesized companion.

type Executor

type Executor interface {
	// contains filtered or unexported methods
}

Executor executes scheduled or adhoc checks

type IntervalScheduler

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

IntervalScheduler schedules checks to be executed on a timer

func NewIntervalScheduler

func NewIntervalScheduler(ctx context.Context, store store.Store, bus messaging.MessageBus, check *types.CheckConfig, cache *EntityCache) *IntervalScheduler

func (*IntervalScheduler) Interrupt

func (s *IntervalScheduler) Interrupt(check *corev2.CheckConfig)

Interrupt refreshes the scheduler with a revised check config.

func (*IntervalScheduler) Start

func (s *IntervalScheduler) Start()

Start starts the IntervalScheduler.

func (*IntervalScheduler) Stop

func (s *IntervalScheduler) Stop() error

Stop stops the IntervalScheduler

func (*IntervalScheduler) Type

func (s *IntervalScheduler) Type() SchedulerType

type IntervalTimer

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

A IntervalTimer handles starting a stopping timers for a given check

func NewIntervalTimer

func NewIntervalTimer(name string, interval uint) *IntervalTimer

NewIntervalTimer establishes new check timer given a name & an initial interval

func (*IntervalTimer) C

func (timerPtr *IntervalTimer) C() <-chan time.Time

C channel emits events when timer's duration has reached 0

func (*IntervalTimer) Next

func (timerPtr *IntervalTimer) Next()

Next reset's timer using interval

func (*IntervalTimer) SetDuration

func (timerPtr *IntervalTimer) SetDuration(cron string, interval uint)

SetDuration updates the interval in which timers are set

func (*IntervalTimer) Start

func (timerPtr *IntervalTimer) Start()

Start sets up a new timer

func (*IntervalTimer) Stop

func (timerPtr *IntervalTimer) Stop()

Stop ends the timer

type Option

type Option func(*Schedulerd) error

Option is a functional option.

type RoundRobinCronScheduler

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

RoundRobinCronScheduler is like CronScheduler, but only schedules checks on a single entity at a time.

func NewRoundRobinCronScheduler

func NewRoundRobinCronScheduler(ctx context.Context, store store.Store, bus messaging.MessageBus, pool *ringv2.Pool, check *corev2.CheckConfig, cache *EntityCache) *RoundRobinCronScheduler

NewRoundRobinCronScheduler creates a new RoundRobinCronScheduler.

func (*RoundRobinCronScheduler) Interrupt

func (s *RoundRobinCronScheduler) Interrupt(check *corev2.CheckConfig)

Interrupt refreshes the scheduler with a revised check config.

func (*RoundRobinCronScheduler) Start

func (s *RoundRobinCronScheduler) Start()

Start starts the scheduler.

func (*RoundRobinCronScheduler) Stop

func (s *RoundRobinCronScheduler) Stop() error

Stop stops the scheduler

func (*RoundRobinCronScheduler) Type

Type returns RoundRobinCronType

type RoundRobinIntervalScheduler

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

func NewRoundRobinIntervalScheduler

func NewRoundRobinIntervalScheduler(ctx context.Context, store store.Store, bus messaging.MessageBus, pool *ringv2.Pool, check *corev2.CheckConfig, cache *EntityCache) *RoundRobinIntervalScheduler

func (*RoundRobinIntervalScheduler) Interrupt

func (s *RoundRobinIntervalScheduler) Interrupt(check *corev2.CheckConfig)

Interrupt refreshes the scheduler with a revised check config.

func (*RoundRobinIntervalScheduler) Start

func (s *RoundRobinIntervalScheduler) Start()

func (*RoundRobinIntervalScheduler) Stop

Stop stops the scheduler

func (*RoundRobinIntervalScheduler) Type

type Scheduler

type Scheduler interface {
	// Start stops the scheduler.
	Start()

	// Stop stops the scheduler.
	Stop() error

	// Interrupt refreshes the state of the scheduler.
	Interrupt(*corev2.CheckConfig)

	// Type returns the scheduler type
	Type() SchedulerType
}

Scheduler is a check scheduler. It is responsible for determining the scheduling interval of a check, given a particular configuration. After Start(), the scheduler is active and will continue to schedule a check according to its schedule. When Interrupt is called, the schedule will be recalculated.

type SchedulerType

type SchedulerType int
const (
	IntervalType SchedulerType = iota
	CronType
	RoundRobinIntervalType
	RoundRobinCronType
)

func GetSchedulerType

func GetSchedulerType(check *corev2.CheckConfig) SchedulerType

GetSchedulerType gets the SchedulerType for a given check config.

func (SchedulerType) String

func (s SchedulerType) String() string

type Schedulerd

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

Schedulerd handles scheduling check requests for each check's configured interval and publishing to the message bus.

func New

func New(c Config, opts ...Option) (*Schedulerd, error)

New creates a new Schedulerd.

func (*Schedulerd) Err

func (s *Schedulerd) Err() <-chan error

Err returns a channel on which to listen for terminal errors.

func (*Schedulerd) Name

func (s *Schedulerd) Name() string

Name returns the daemon name

func (*Schedulerd) Start

func (s *Schedulerd) Start() error

Start the Scheduler daemon.

func (*Schedulerd) Stop

func (s *Schedulerd) Stop() error

Stop the scheduler daemon.

Jump to

Keyboard shortcuts

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