scheduler

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Scheduler

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

Scheduler represents a job scheduler.

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler creates a new instance of Scheduler.

func (*Scheduler) AddTask

func (s *Scheduler) AddTask(id string, cronExpr string, task func()) error

AddTask adds a task to the scheduler with the specified ID, cron expression, and task function. If a task with the same ID already exists, it does nothing and returns nil. Otherwise, it schedules the task to run at the specified cron expression and returns nil.

func (*Scheduler) AddTaskWithInterval

func (s *Scheduler) AddTaskWithInterval(id string, interval time.Duration, task func()) error

AddTaskWithInterval adds a task with the specified interval to the scheduler. It takes an ID, interval duration, and a task function as parameters. If a task with the same ID already exists, it does nothing and returns nil. Otherwise, it schedules the task to run at the specified interval and returns nil.

func (*Scheduler) RemoveTask

func (s *Scheduler) RemoveTask(id string)

RemoveTask removes a task from the scheduler with the specified ID.

func (*Scheduler) ScheduleOnce

func (s *Scheduler) ScheduleOnce(id string, when time.Time, task func())

ScheduleOnce schedules a task to run once at the specified time. If a task with the same ID is already scheduled, it cancels the existing timer and schedules the new task.

func (*Scheduler) Start

func (s *Scheduler) Start(ctx context.Context)

Start starts the scheduler in a separate goroutine. It takes a context as a parameter to allow graceful shutdown.

func (*Scheduler) Stop

func (s *Scheduler) Stop()

Stop stops the scheduler and waits for all tasks to complete.

type SchedulerInterface

type SchedulerInterface interface {
	AddTask(id string, cronExpr string, task func()) error
	RemoveTask(id string)
	ScheduleOnce(id string, when time.Time, task func())
	Start(ctx context.Context)
	Stop()
	AddTaskWithInterval(id string, interval time.Duration, task func()) error
}

Jump to

Keyboard shortcuts

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