hajobs

package module
v0.0.0-...-7df2eab Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 8 Imported by: 0

README

hajobs-go

Highly available background jobs for all kinds of systems.

Documentation

Index

Constants

View Source
const (
	CronMinutely            = "* * * * *"
	CronHourly              = "0 * * * *"
	CronDaily               = "0 0 * * *"
	CronMonthly             = "0 0 0 1 * * *"
	CronEveryFiveMinutes    = "*/5 * * * *"
	CronEveryFifteenMinutes = "*/15 * * * *"
	CronEveryTenSeconds     = "*/10 * * * * * *"
	CronNightlyAt3          = "0 3 * * *"
	CronNightlyAt2          = "0 2 * * *"
	CronNightlyAt4          = "0 4 * * *"
	CronNightlyAt5          = "0 5 * * *"
	CronNightlyAt6          = "0 6 * * *"
	CronNightlyAt7          = "0 7 * * *"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type JobCfg

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

JobCfg contains data to create a job if not present yet.

type JobInfo

type JobInfo struct {
	Name     string `json:"name"`
	Checksec int    `json:"checksec"`
	Enabled  bool   `json:"enabled"`
	//owner      string
	Lockttlsec  int `json:"lockttlsec"`
	Schedule    *cronexpr.Expression
	Cronexpr    string
	LastUpdated time.Time
	State       []byte
}

JobInfo metadata

func ToJobInfo

func ToJobInfo(name string, c JobCfg) (JobInfo, error)

type JobsRepo

type JobsRepo interface {
	GetJobinfo(ctx context.Context, name string) (*JobInfo, error)
	SaveState(ctx context.Context, name string, state []byte) error
	Commit(ctx context.Context, name string, state []byte) error
	CreateJob(ctx context.Context, name string, jobCfg JobCfg) error
}

type Lock

type Lock interface {
	Unlock(context context.Context) error
}

type LockRepo

type LockRepo interface {
	// Lock - name is the lock Name
	// owner is used to indicate the current holder of a lock (eg the hostname)
	// interval is the lock TTL
	// returns lock object that is a handle for unlocking a lock
	Lock(context context.Context, name string, owner string, interval time.Duration) (Lock, error, <-chan error)
}

type Manager

type Manager interface {
	Register(name string, schedule string, run func(ctx context.Context, commitFunc func(state []byte) error, state []byte) ([]byte, error))
	StartAll()
}

func NewManager

func NewManager(ctx context.Context, id string, jobsRepo JobsRepo, lockRepo LockRepo) Manager

NewManager creates a new job manager. The provided context will be used to execute the individual job functions. In order to cancel all job processing, the provided context can be cancelled.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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