jobticker

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: MIT Imports: 9 Imported by: 1

README

Common Go Job ticker support code shared between my projects

GoDoc Build Coverage

License

This project is subject to the MIT License. See LICENSE information for details.

Documentation

Overview

Package jobticker provides functions and types to setup and trigger background jobs on a pre-defined ticker.

Package jobticker provides functions and types to setup and trigger background jobs on a pre-defined ticker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JobFunc

type JobFunc func(ctx context.Context, last, now time.Time) error

JobFunc defines the jobs to execute. It is called with the execution context as well as the last and current tick of the job ticker.

type ScheduleSpec

type ScheduleSpec string

ScheduleSpec defines a schedule based on a cron expression ([https://en.wikipedia.org/wiki/Cron]).

ScheduleSpec implements encoding.TextMarshaler and encoding.TextUnmarshaler.

func (ScheduleSpec) InInterval

func (spec ScheduleSpec) InInterval(from, to time.Time) bool

InInterval determines whether this schedule lies within the given time interval.

func (ScheduleSpec) MarshalText

func (spec ScheduleSpec) MarshalText() ([]byte, error)

see encoding.TextMarshaler.

func (ScheduleSpec) String

func (spec ScheduleSpec) String() string

String gets the schedule expression as string.

func (*ScheduleSpec) UnmarshalText

func (spec *ScheduleSpec) UnmarshalText(text []byte) error

see encoding.TextUnmarshaler.

type SequentialQueue

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

SequentialQueue defines a simple sequential job ticker. Jobs are executed in sequential order every time the ticker fires.

func StartSequential

func StartSequential(ctx context.Context, schedule, deadline time.Duration, jobs ...JobFunc) *SequentialQueue

StartSequential starts a new sequential job ticker using the given schedule, deadline limit and jobs.

func (*SequentialQueue) AddJobs

func (q *SequentialQueue) AddJobs(jobs ...JobFunc)

AddJobs adds the given jobs to this job ticker. The jobs are picked up the next time the job ticker fires.

func (*SequentialQueue) Shutdown

func (q *SequentialQueue) Shutdown(ctx context.Context) error

Shutdown stops the job ticker and releases any related resources.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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