scheduler

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2021 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package scheduler provides a job scheduler for periodically functions.

Index

Constants

View Source
const (
	StatusRunning    = "Scheduler is running!"
	StatusNotRunning = "Scheduler is not running"
)

Status messages.

View Source
const (
	GoCron = "gocron"
)

Pre-defined scheduler providers.

Variables

This section is empty.

Functions

func Register

func Register(name string, provider providerFn) error

Register a new scheduler provider by name.

Types

type Provider

type Provider interface {
	// Start the scheduler executor.
	Start()
	// Stop the scheduler executor.
	Stop()
	// Status of the scheduler
	Status() string
	// Jobs of the scheduler will be returned.
	Jobs() []ProviderJobDetail
	// Every will create a new Job with the given interval.
	// int, string and time.duration should be possible.
	Every(interval interface{}) ProviderJob
}

Provider interface.

func New

func New(provider string, options interface{}) (Provider, error)

New returns a specific scheduler provider by its name and given options. For the specific provider options please check out the provider details. If the provider is not registered an error will return.

type ProviderJob

type ProviderJob interface {
	// Second will be set as unit.
	Second() ProviderJob
	// Minute will be set as unit.
	Minute() ProviderJob
	// Day will be set as unit.
	Day() ProviderJob
	Monday() ProviderJob
	Tuesday() ProviderJob
	Wednesday() ProviderJob
	Thursday() ProviderJob
	Friday() ProviderJob
	Saturday() ProviderJob
	Sunday() ProviderJob
	// At defines the runtime. (Format HH:MM or HH:MM:SS)
	At(string) ProviderJob
	// Week will be set as unit.
	Week() ProviderJob
	// Month will be set as unit.
	// If no day is given, 1 will be set as default.
	Month(dayOfMonth ...int) ProviderJob
	// Name of the job.
	Name(name string) ProviderJob
	// Tag(s) to categorize the job.
	Tag(tag ...string) ProviderJob
	// Singleton will not spawn a new job if the old one is not finished yet.
	Singleton() ProviderJob
	// Do defines the function which should be called. Parameter can be added.
	Do(jobFun interface{}, params ...interface{}) error
}

Job interface.

type ProviderJobDetail

type ProviderJobDetail interface {
	// Name of the Job
	Name() string
	// Counter of the job runs.
	Counter() int
	// Tags of the job.
	Tags() []string
	// LastRun of the job.
	LastRun() time.Time
	// NextRun of the job.
	NextRun() time.Time
}

JobDetail interface

Jump to

Keyboard shortcuts

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