goscheduler

package
v0.0.0-...-9f3d2d7 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2021 License: LGPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SIGTASKTERM = 0x1
)

Goroutine task signals

Variables

View Source
var (
	//ErrorBadTimeFormat is rise when time format is bad for example create a task that run at 52 hour
	ErrorBadTimeFormat error = errors.New("Bad Time Format")
	//ErrorTaskNotFound rised when no task found in the scheduler
	ErrorTaskNotFound error = errors.New("Task not found in the scheduler")
)

Functions

This section is empty.

Types

type Scheduler

type Scheduler struct {
	Tasks          []*Task
	UpdateInterval int
	WarningLogger  *log.Logger
	InfoLogger     *log.Logger
	ErrorLogger    *log.Logger
}

Scheduler represent the scheduler

func NewScheduler

func NewScheduler(warninglogger, infologger, errorlogger *log.Logger) Scheduler

NewScheduler is constructor of scheduler

func (*Scheduler) Clear

func (s *Scheduler) Clear()

Clear remove all task in the scheduler

func (*Scheduler) DisableTaskByID

func (s *Scheduler) DisableTaskByID(id int) error

DisableTaskByID disable task on the scheduler but don't delete it

func (*Scheduler) EnableTaskByID

func (s *Scheduler) EnableTaskByID(id int) error

EnableTaskByID enable a task that has been disabled

func (*Scheduler) GetDisableTasks

func (s *Scheduler) GetDisableTasks() []*Task

GetDisableTasks return disable task

func (*Scheduler) GetEnableTasks

func (s *Scheduler) GetEnableTasks() []*Task

GetEnableTasks return enabled task

func (*Scheduler) GetTasks

func (s *Scheduler) GetTasks() []*Task

GetTasks return all task managed by scheduler

func (*Scheduler) NewScheduleTask

func (s *Scheduler) NewScheduleTask(id int, name string, action func(v ...interface{}), signal chan int, hour, minute, second int) error

NewScheduleTask create a new schedule task and add it in the scheduler

func (*Scheduler) RemoveTaskByID

func (s *Scheduler) RemoveTaskByID(id int) error

RemoveTaskByID remove task in the scheduler by it's ID

func (*Scheduler) RunAsync

func (s *Scheduler) RunAsync()

RunAsync start the scheduler not blocking

type Task

type Task struct {
	ID         int
	Name       string
	Action     func(v ...interface{})
	Enable     bool
	Scheduled  bool
	Timer      *time.Timer
	NextRun    time.Time
	LastRun    time.Time
	Hour       int
	Minute     int
	Second     int
	TaskSignal chan int
}

Task represent a task in scheduler

func (*Task) Run

func (t *Task) Run(s string)

Run execute the task

Jump to

Keyboard shortcuts

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