croncontroller

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CronWorkerInterval is the interval between checking if JobConfigs should be
	// enqueued. We only really need this as small as once per second.
	CronWorkerInterval = time.Second
)

Variables

View Source
var (
	// Clock is exposed for unit tests. Note that multiple components may share
	// references to the same clock in this package.
	Clock clock.Clock = clock.RealClock{}
)

Functions

func CronTimerUntil

func CronTimerUntil(work func(), timestep time.Duration, stopCh <-chan struct{})

CronTimerUntil runs work every timestep until stopCh is signaled. The work function will first be called immediately on initial call, followed by rounding up to the nearest timestep for every subsequent step. The smallest timestep that is admissible is a second.

func IsScheduleEqual

func IsScheduleEqual(orig, updated *execution.ScheduleSpec) (bool, error)

IsScheduleEqual returns true if the ScheduleSpec is not equal and should be updated. This equality check is only true in the context of the CronController.

func JobConfigKeyFunc

func JobConfigKeyFunc(config *execution.JobConfig, scheduleTime time.Time) (string, error)

JobConfigKeyFunc returns a key to return the key for a JobConfig with the scheduled timestamp.

func ParseUnix

func ParseUnix(unixString string) (time.Time, error)

ParseUnix parses a Unix timestamp (in seconds) from a string.

func SplitJobConfigKeyName

func SplitJobConfigKeyName(key string) (name string, ts time.Time, err error)

SplitJobConfigKeyName splits a key into name and scheduled timestamp for a JobConfig.

Types

type Context

type Context struct {
	controllercontext.ContextInterface
	// contains filtered or unexported fields
}

Context extends the common controllercontext.Context.

func NewContext

func NewContext(context controllercontext.ContextInterface) *Context

type Controller

type Controller struct {
	*Context
	// contains filtered or unexported fields
}

Controller is responsible for creating new Jobs from JobConfigs based on their cron schedule.

func NewController

func NewController(
	ctrlContext controllercontext.ContextInterface,
	concurrency *configv1.Concurrency,
) (*Controller, error)

func (*Controller) GetHealth

func (c *Controller) GetHealth() controllermanager.HealthStatus

func (*Controller) Run

func (c *Controller) Run(ctx context.Context) error

func (*Controller) Shutdown

func (c *Controller) Shutdown(ctx context.Context)

type CronWorker

type CronWorker struct {
	*Context
	*Schedule
}

CronWorker enqueues Job names to be scheduled, based on the cron schedule of the config. It will enqueue one item for each schedule interval, which is a 1:1 correspondence with a Job to be created.

func NewCronWorker

func NewCronWorker(ctrlContext *Context) *CronWorker

func (*CronWorker) Start

func (w *CronWorker) Start(stopCh <-chan struct{})

func (*CronWorker) WorkerName

func (w *CronWorker) WorkerName() string

type Factory

type Factory struct{}

func NewFactory

func NewFactory() *Factory

func (*Factory) Name

func (f *Factory) Name() string

func (*Factory) New

type InformerWorker

type InformerWorker struct {
	*Context
}

InformerWorker receives events from the informer and enqueues work to be done for the controller.

func NewInformerWorker

func NewInformerWorker(ctrlContext *Context) *InformerWorker

func (*InformerWorker) WorkerName

func (w *InformerWorker) WorkerName() string

type Reconciler

type Reconciler struct {
	*Context
	// contains filtered or unexported fields
}

func NewReconciler

func NewReconciler(ctrlContext *Context, concurrency *configv1.Concurrency) *Reconciler

func (*Reconciler) Concurrency

func (w *Reconciler) Concurrency() int

func (*Reconciler) MaxRequeues

func (w *Reconciler) MaxRequeues() int

func (*Reconciler) Name

func (w *Reconciler) Name() string

func (*Reconciler) SyncOne

func (w *Reconciler) SyncOne(ctx context.Context, namespace, name string, _ int) error

type Schedule

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

Schedule is a thread-safe store for the next schedule time of JobConfigs.

func NewSchedule

func NewSchedule(ctrlContext controllercontext.ContextInterface) *Schedule

func (*Schedule) BumpNextScheduleTime

func (w *Schedule) BumpNextScheduleTime(
	jobConfig *execution.JobConfig, fromTime time.Time, expr *cronexpr.Expression,
)

BumpNextScheduleTime updates the next schedule time of a JobConfig.

func (*Schedule) FlushNextScheduleTime

func (w *Schedule) FlushNextScheduleTime(jobConfig *execution.JobConfig)

FlushNextScheduleTime flushes the next schedule time for a JobConfig, causing it to be recomputed on the next time GetNextScheduleTime is called.

func (*Schedule) GetNextScheduleTime

func (w *Schedule) GetNextScheduleTime(
	jobConfig *execution.JobConfig, fromTime time.Time, expr *cronexpr.Expression,
) time.Time

GetNextScheduleTime returns the next expected schedule time for a JobConfig. This encapsulates the core logic for deciding if a Job should be enqueued. Returns a zero-value time if the cron expression does not have any timestamp in the future. The cron expression is interpreted relative to the timezone of fromTime.

Jump to

Keyboard shortcuts

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