goscheduler

package module
v0.0.0-...-0d0437f Latest Latest
Warning

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

Go to latest
Published: Dec 14, 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() {
          sc := goscheduler.NewScheduler()
          //normal job
          sc.AddJob(func(tt string) { fmt.Println(tt) }, time.Now().Add(5*time.Second), false, time.Second, "5 sec")
    
          // job repeated
          sc.Job(func(tt string) { fmt.Println(tt) }, "repeat").Args("repeat").RepeatEvery(3 * time.Second)
    
          // job repeated
          sc.Job(func(tt string) { fmt.Println(tt) }, "lifetime").Args("lifetime").RepeatEvery(3 * time.Second).LifeTime(time.Now().Add(20 * time.Second))
    
          <-sc.Start()
      }
    

TODO:

  • Running x task at a time to avoid overwhelming
  • 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 {
	// contains filtered or unexported fields
}

Scheduler structure.

func NewScheduler

func NewScheduler() *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