workers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package workers for job worker managed by controller-runtime manager

Index

Constants

This section is empty.

Variables

View Source
var ConfigWatcherFunc = func(cw *CronWorker) func(c *config.Config) {
	return func(c *config.Config) {
		for i, job := range cw.jobs {
			spec := metav1alpha1.DataMap(c.Data).MustStringVal(job.name, "0 0 * * *")
			newEntryID, err := cw.cron.AddJob(spec, job.funcJob)
			if err != nil {
				cw.Errorw("config watcher update cron job error", "err", err)
				return
			}
			if job.entryID > 0 {
				cw.cron.Remove(job.entryID)
			}
			cw.jobs[i].entryID = newEntryID
			cw.Debugf("ConfigWatcherFunc fallback: set job %s cron spec to %s", job.name, spec)
		}
	}
}

ConfigWatcherFunc is the default watch func

Functions

This section is empty.

Types

type CronWorker

type CronWorker struct {
	Runners []JobRunnable

	*zap.SugaredLogger
	// contains filtered or unexported fields
}

CronWorker maintains a list of runners and dedicated to cron watched by configManager

func (*CronWorker) CheckSetup

func (cw *CronWorker) CheckSetup(ctx context.Context, manager manager.Manager, logger *zap.SugaredLogger) error

func (*CronWorker) Name

func (cw *CronWorker) Name() string

func (*CronWorker) NeedLeaderElection

func (cw *CronWorker) NeedLeaderElection() bool

NeedLeaderElection indicates cron worker

func (*CronWorker) Setup

func (cw *CronWorker) Setup(ctx context.Context, manager manager.Manager, logger *zap.SugaredLogger) error

func (*CronWorker) Start

func (cw *CronWorker) Start(ctx context.Context) error

Start starts cron and waits for context cancellation

type JobRunnable

type JobRunnable interface {
	Setup(ctx context.Context, kclient client.Client, restClient *resty.Client) error
	// JobName is identical to config key name from configManager
	JobName() string
	// RunFunc returns the cron callback func to be invoked
	RunFunc(ctx context.Context) func()
}

JobRunnable provides runnable methods to managed by worker

Jump to

Keyboard shortcuts

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