cron

package module
v0.0.0-...-e6f50f7 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cron provides a cron-like job scheduler.

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 represents a scheduled task in the scheduler.

type Scheduler

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

Scheduler manages a collection of jobs and ensures they are run at the scheduled times.

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler creates and returns a new Scheduler. It immediately starts the scheduling goroutine.

func (*Scheduler) AddJob

func (s *Scheduler) AddJob(schedule string, task func()) (*Job, error)

AddJob adds a new job to the scheduler. The schedule should be a cron-like string with five fields: minute, hour, day of month, month, and day of week. It returns a pointer to the created Job and an error if the schedule is invalid.

func (*Scheduler) RemoveJob

func (s *Scheduler) RemoveJob(job *Job)

RemoveJob removes a job from the scheduler. If the job is not in the scheduler (i.e., has already been removed), this operation is a no-op.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop terminates the scheduler, preventing any new jobs from running. It waits for any currently running jobs to complete before returning.

func (*Scheduler) UpdateJob

func (s *Scheduler) UpdateJob(job *Job, schedule string) error

UpdateJob updates the schedule of an existing job. It returns an error if the job is not found in the scheduler or if the new schedule is invalid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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