Scheduler

package module
Version: v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

README

Scheduler

Go Reference

Scheduler package is a zero-dependency scheduling library for Go

Install

go get -u github.com/Ja7ad/Scheduler

Features

  • Scheduling your functions
  • In a scheduler instance, you can run more than one thousand jobs at a time (Max Job is 10.000)
  • In the form of Safely, you can run your jobs and if a panic occurs, your jobs will be recovered and reported to the console (func (j *Job) DoJobSafely(jobFunction interface{}, params ...interface{}) error)
  • Multiple scheduler instances can be run simultaneously

Example

More Example in

package main

import (
	"fmt"
	"github.com/Ja7ad/Scheduler"
)

var (
	Sched = Scheduler.NewScheduler()
)

func main() {
	if err := Sched.Every(5).Second().Do(Greeting); err != nil {
		panic(err)
	}

	<-Sched.Start()
}

func Greeting() {
	fmt.Println("Hello, World!")
}

Contributing

We'd love to see your contribution to the scheduler! you can contribute by following these steps :

  1. Fork the repository
  2. Create a new branch
  3. Make your changes
  4. Commit your changes
  5. Push your changes to the remote repository
  6. Create a pull request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeTimeLocation

func ChangeTimeLocation(location *time.Location)

ChangeTimeLocation change the location of a time

func Clear

func Clear()

Clear all scheduled jobs

func Every

func Every(interval uint64) *job.Job

Every schedules a new periodic job running in specific interval

func Jobs

func Jobs() []*job.Job

Jobs returns the list of job from the defaultScheduler

func NextRun

func NextRun() (job *job.Job, time time.Time)

NextRun gets the next running time

func Remove

func Remove(j interface{})

Remove a specific job

func RunAll

func RunAll()

RunAll runs all jobs

func RunAllWithDelay

func RunAllWithDelay(d int)

RunAllWithDelay runs all jobs with a delay

func RunPending

func RunPending()

RunPending runs all pending jobs

func Scheduled

func Scheduled(j interface{}) bool

Scheduled checks if specific job j was already added

func SetLocker added in v0.2.0

func SetLocker(l job.Locker)

SetLocker sets a locker implementation

func Start

func Start() chan bool

Start run all jobs that are scheduled to run

Types

type Scheduler

type Scheduler struct {
	JobList  [global.MaxJobs]*job.Job // Jobs is the array of jobs
	JobSize  int                      // JobSize is the number of jobs
	Location *time.Location           // Location is the location of the scheduler
}

Scheduler is the main struct of the scheduler

func NewScheduler

func NewScheduler() *Scheduler

NewScheduler creates a new scheduler

func (*Scheduler) ChangeLocation

func (s *Scheduler) ChangeLocation(newLocation *time.Location)

ChangeLocation changes the default time location of the scheduler

func (*Scheduler) Clear

func (s *Scheduler) Clear()

Clear removes all scheduled jobs

func (*Scheduler) Every

func (s *Scheduler) Every(interval uint64) *job.Job

Every schedules a new job to run every duration

func (*Scheduler) GetRunnableJobs

func (s *Scheduler) GetRunnableJobs() (runningJobs [global.MaxJobs]*job.Job, n int)

GetRunnableJobs returns a list of jobs that are ready to run

func (*Scheduler) Jobs

func (s *Scheduler) Jobs() []*job.Job

Jobs returns list of jobs from scheduler

func (*Scheduler) Len

func (s *Scheduler) Len() int

Len returns the number of jobs in the scheduler

func (*Scheduler) Less

func (s *Scheduler) Less(i, j int) bool

Less returns true if the job at index i is less than the job at index j

func (*Scheduler) NextRun

func (s *Scheduler) NextRun() (*job.Job, time.Time)

NextRun returns the next run time of the job at index i

func (*Scheduler) Remove

func (s *Scheduler) Remove(j interface{})

Remove job by function

func (*Scheduler) RemoveByCondition

func (s *Scheduler) RemoveByCondition(remove func(*job.Job) bool)

RemoveByCondition removes specific job j by condition

func (*Scheduler) RemoveByRef

func (s *Scheduler) RemoveByRef(j *job.Job)

RemoveByRef removes specific job j by reference

func (*Scheduler) RemoveByTag

func (s *Scheduler) RemoveByTag(t string)

RemoveByTag removes specific job j by tag

func (*Scheduler) RunAll

func (s *Scheduler) RunAll()

RunAll runs all jobs

func (*Scheduler) RunAllWithDelay

func (s *Scheduler) RunAllWithDelay(d int)

RunAllWithDelay runs all jobs with a delay

func (*Scheduler) RunPending

func (s *Scheduler) RunPending()

RunPending runs all pending jobs

func (*Scheduler) Scheduled

func (s *Scheduler) Scheduled(j interface{}) bool

Scheduled returns true if job j is scheduled

func (*Scheduler) Start

func (s *Scheduler) Start() chan bool

Start starts all pending jobs

func (*Scheduler) Swap

func (s *Scheduler) Swap(i, j int)

Swap swaps the two jobs

Directories

Path Synopsis
_example

Jump to

Keyboard shortcuts

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