Documentation ¶
Index ¶
- type Scheduler
- func (s *Scheduler) AddTask(id string, cronExpr string, task func()) error
- func (s *Scheduler) AddTaskWithInterval(id string, interval time.Duration, task func()) error
- func (s *Scheduler) RemoveTask(id string)
- func (s *Scheduler) ScheduleOnce(id string, when time.Time, task func())
- func (s *Scheduler) Start(ctx context.Context)
- func (s *Scheduler) Stop()
- type SchedulerInterface
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 ¶
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 ¶
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 ¶
RemoveTask removes a task from the scheduler with the specified ID.
func (*Scheduler) ScheduleOnce ¶
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.