Skip to content

Latest commit

 

History

History
71 lines (64 loc) · 1.69 KB

README.md

File metadata and controls

71 lines (64 loc) · 1.69 KB

go-quartz

Build Status Go Report Card

A go scheduling library

About

Inspired by quartz java scheduler.

Library building blocks

Job interface. Should be implemented by custom jobs for further scheduling

type Job interface {
	Execute()
	Description() string
	Key() int
}

Implemented Jobs

  • ShellJob
  • CurlJob

Scheduler interface

type Scheduler interface {
	//start scheduler
	Start()
	//schedule Job with given Trigger
	ScheduleJob(job Job, trigger Trigger) error
	//get all scheduled Job keys
	GetJobKeys() []int
	//get scheduled Job metadata
	GetScheduledJob(key int) (*ScheduledJob, error)
	//remove Job from execution queue
	DeleteJob(key int) error
	//clear all scheduled jobs
	Clear()
	//shutdown scheduler
	Stop()
}

Implemented Schedulers

  • StdScheduler

Trigger interface

type Trigger interface {
	NextFireTime(prev int64) (int64, error)
	Description() string
}

Implemented Triggers

  • CronTrigger
  • SimpleTrigger
  • RunOnceTrigger

Examples

sched := quartz.NewStdScheduler()
sched.Start()
cronTrigger, _ := quartz.NewCronTrigger("1/5 * * * * *")
shellJob := quartz.NewShellJob("ls -la")
curlJob, _ := quartz.NewCurlJob(http.MethodGet, "http://worldclockapi.com/api/json/est/now", "", nil)
sched.ScheduleJob(shellJob, cronTrigger)
sched.ScheduleJob(curlJob, quartz.NewSimpleTrigger(time.Second*7))
sched.Stop()

More could be found in the examples directory.

License

Licensed under the MIT License.