periodicprocessor

package
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package periodicprocessor provides cron-based periodic job scheduling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

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

Job describes a producer that periodically inserts regular queue tasks.

func NewCronJob

func NewCronJob(
	name string,
	cronSpec string,
	cronLocation *time.Location,
	factory TaskFactory,
	opts ...JobOptions,
) (*Job, error)

NewCronJob creates a periodic job from a standard 5-field cron spec.

func NewJob

func NewJob(
	name string,
	schedule Scheduler,
	factory TaskFactory,
	opts ...JobOptions,
) (*Job, error)

NewJob creates a periodic job from a schedule and task factory.

func (*Job) Name

func (j *Job) Name() string

Name returns the periodic job name.

type JobOptions

type JobOptions func(*Job)

JobOptions configures a periodic job.

func WithRunOnStart

func WithRunOnStart() JobOptions

WithRunOnStart makes a periodic job enqueue one task when the scheduler starts.

type Processor

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

Processor runs one periodic job schedule.

func NewProcessor

func NewProcessor(taskQueueManager TaskQueueManager, job *Job) *Processor

NewProcessor creates a periodic job processor.

func (*Processor) Name

func (p *Processor) Name() string

Name returns the processor name.

func (*Processor) Run

func (p *Processor) Run(ctx context.Context) error

Run starts the periodic job processor.

func (*Processor) Stop

func (p *Processor) Stop()

Stop gracefully shuts down the processor.

type Scheduler

type Scheduler interface {
	Next(time.Time) time.Time
}

Scheduler calculates the next run time for a periodic job.

func CronSchedule

func CronSchedule(spec string, location *time.Location) (Scheduler, error)

CronSchedule creates a schedule from a standard 5-field cron spec.

type SchedulerFunc

type SchedulerFunc func(time.Time) time.Time

SchedulerFunc adapts a function to the Scheduler interface.

func (SchedulerFunc) Next

func (f SchedulerFunc) Next(t time.Time) time.Time

Next returns the next scheduled run time.

type TaskFactory

type TaskFactory func(ctx context.Context) (*entity.Task, error)

TaskFactory creates a task for a scheduled run.

type TaskQueueManager

type TaskQueueManager interface {
	AddTaskToQueue(ctx context.Context, task *entity.Task) error
}

TaskQueueManager adds generated periodic job tasks to the queue.

Jump to

Keyboard shortcuts

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