goscheduler

package module
v0.0.0-...-32e9cea Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2018 License: MIT Imports: 8 Imported by: 0

README

goScheduler

goScheduler is a Golang package for scheduling tasks. This tasks can be run once in a selected time ,repeatedly or repeatedly with a lifetime. All tasks will be run concurrently. Task properties:

  • Function - function that will be run

  • Arguments - parameters that will be passed to the function

  • Execution time - time when task starts executing

  • RepeatTime - how often function will be run

  • LifeTime - time that task will be available

      package main
    
      import (
          "fmt"
          "time"
          "github.com/mariopinderist/goscheduler"
      )
    
      func main() {
          // If you wish to limit the number of tasks running at a time, enter the number as an argument while calling NewScheduler
          // The default value is max 100 tasks at a time ex. sc := goscheduler.NewScheduler(20)
    
          sc.AddFunction(func(tt string) { fmt.Println("first") }, "fnc1")
         	_ = sc.AddJobById("fnc1", time.Now().Add(5*time.Second), false, time.Second,"test1")
    
         	// job repeated
         	sc.AddFunction(func(tt string) { fmt.Println(tt) }, "fnc2")
         	_ = sc.AddJobById("fnc2", time.Now().Add(10*time.Second), false, time.Second,"test2")
    
    
         	// job repeated
         	sc.AddFunction(func(tt string) { fmt.Println(tt) }, "fnc3")
         	_ = sc.AddJobById("fnc3", time.Now().Add(15*time.Second), false, time.Second,"test3")
    
         	<-sc.Start()
      }
    

TODO:

  • Prioritize tasks

Documentation

Index

Constants

View Source
const BUCKET_NOT_EXIST = "bucket does not exist"
View Source
const NO_JOBS_IN_DB = "There are no jobs in database"

Variables

This section is empty.

Functions

This section is empty.

Types

type Job

type Job struct {
	FunctionId  string
	Arguments   []interface{}
	ExecTime    time.Time
	Repetitive  bool
	RepeatTime  time.Duration
	HasLifetime bool
	Lifetime    time.Time
}

Job Structure.

func (*Job) Args

func (job *Job) Args(args ...interface{}) *Job

Add arguments to Job.

func (*Job) ExecutionTime

func (job *Job) ExecutionTime(execTime time.Time) *Job

Set execution time of the Job.

func (*Job) LifeTime

func (job *Job) LifeTime(lifeTime time.Time) *Job

Set time that the Job will be running.

func (*Job) RepeatEvery

func (job *Job) RepeatEvery(repeatTime time.Duration) *Job

Set reputation of the Job.

type Scheduler

type Scheduler struct {
	MaxCon int
	// contains filtered or unexported fields
}

Scheduler structure.

func NewScheduler

func NewScheduler(opts ...int) *Scheduler

Create Scheduler instance.

func (*Scheduler) AddFunction

func (scheduler *Scheduler) AddFunction(function interface{}, functionId string)

Add functions to scheduler.

func (*Scheduler) AddJobById

func (scheduler *Scheduler) AddJobById(functionId string, execTime time.Time, repetitive bool, repeatTime time.Duration, args ...interface{}) error

Add Job to scheduler.

func (*Scheduler) CleanJobs

func (scheduler *Scheduler) CleanJobs()

Remove all jobs of the scheduler.

func (*Scheduler) DeleteJob

func (scheduler *Scheduler) DeleteJob(jobId string)

Delete a Job by id.

func (Scheduler) GetJobsFromBolt

func (scheduler Scheduler) GetJobsFromBolt() error

func (*Scheduler) Job

func (scheduler *Scheduler) Job(functionId string, jobId string) *Job

Create Job instance.

func (*Scheduler) Start

func (scheduler *Scheduler) Start() chan bool

Start the Scheduler.

Jump to

Keyboard shortcuts

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