cronjob

package
v0.0.0-...-3e5e6b6 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunCronJob

func RunCronJob(ctx context.Context, cfg ElectionConfig, job CronJob) error

RunCronJob runs a CronJob and blocks. If cfg.LeaseEnabled is true then only one pod (if application is scaled) will run the cron job. This is done using leader election from k8s with leases. Returns error in case of bad configuration or bad connection to k8s cluster

Types

type CronJob

type CronJob struct {
	Name           string
	Fn             func(ctx context.Context)
	SchedulePeriod time.Duration
}

CronJob represents a job that executes Fn on every SchedulePeriod.

type ElectionConfig

type ElectionConfig struct {
	LeaseLockName      string        `envconfig:"APP_ELECTION_LEASE_LOCK_NAME"`
	LeaseLockNamespace string        `envconfig:"APP_ELECTION_LEASE_LOCK_NAMESPACE"`
	LeaseDuration      time.Duration `envconfig:"optional,default=60s,APP_ELECTION_LEASE_DURATION"`
	RenewDeadline      time.Duration `envconfig:"optional,default=15s,APP_ELECTION_RENEW_DEADLINE"`
	RetryPeriod        time.Duration `envconfig:"optional,default=5s,APP_ELECTION_RETRY_PERIOD"`
	ElectionEnabled    bool          `envconfig:"optional,default=true,APP_ELECTION_ENABLED"`
	ClientConfig       kubernetes.Config
}

ElectionConfig configuration for k8s leader election with lease

Jump to

Keyboard shortcuts

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