goscheduler

package module
v0.0.0-...-45ff61a Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2021 License: LGPL-3.0 Imports: 5 Imported by: 1

README

Goscheduler

Simple scheduler write in go. With this scheduler, you can schedule task that run at specific time for example run a task every day at 8:30:00

Items

Library used 2 main structures, the Scheduler and the Task

The goal of the scheduler is to hold the list of task that shoud be scheduled and start them async. The scheduler is build to run async also, so you need to block your main program.

The task are the action that are schedule

Documentation

Index

Constants

View Source
const (
	TaskExecutionStatusOK      = 0x0
	TaskExecutionStatusFailed  = 0x1
	TaskExecutionStatusPending = 0x2
)
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")
)

DefaultScheduler is the default scheduler without any log

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) GetTaskByID

func (s *Scheduler) GetTaskByID(id int) *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{}) error, 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{}) error
	Enable              bool
	Scheduled           bool
	Timer               *time.Timer
	NextRun             time.Time
	LastRun             time.Time
	Hour                int
	Minute              int
	Second              int
	TaskSignal          chan int
	TaskExecutionStatus int
}

Task represent a task in scheduler

func (*Task) Run

func (t *Task) Run()

Run execute the task

Jump to

Keyboard shortcuts

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