Job scheduling made easy.

scheduler

GoDoc Build Status Coverage Status

Job scheduling made easy.

Scheduler allows you to schedule recurrent jobs with an easy-to-read syntax.

Inspired by the article Rethinking Cron and the schedule python module.

How to use?

package main

import (
	"fmt"
	"runtime"
	"time"

	"github.com/carlescere/scheduler"
)

func main() {
	job := func() {
		t := time.Now()
		fmt.Println("Time's up! @", t.UTC())
	}
      // Run every 2 seconds but not now.
	scheduler.Every(2).Seconds().NotImmediately().Run(job)
      
      // Run now and every X.
	scheduler.Every(5).Minutes().Run(job)
	scheduler.Every().Day().Run(job)
	scheduler.Every().Monday().At("08:30").Run(job)
      
      // Keep the program from not exiting.
	runtime.Goexit()
}

How it works?

By specifying the chain of calls, a Job struct is instantiated and a goroutine is starts observing the Job.

The goroutine will be on pause until:

  • The next run scheduled is due. This will cause to execute the job.
  • The SkipWait channel is activated. This will cause to execute the job.
  • The Quit channel is activated. This will cause to finish the job.

Not immediate recurrent jobs

By default the behaviour of the recurrent jobs (Every(N) seconds, minutes, hours) is to start executing the job right away and then wait the required amount of time. By calling specifically .NotImmediately() you can override that behaviour and not execute it directly when the function Run() is called.

scheduler.Every(5).Minutes().NotImmediately().Run(job)

License

Distributed under MIT license. See LICENSE for more information.

Owner
Carles Cerezo Guzmán
I bash my keyboard and hope for the best. Software engineer at @YieldifyLabs
Carles Cerezo Guzmán
Comments
  • indirect vulnerability

    indirect vulnerability

    Unfortunately, the scheduler uses yaml.v2 library, which has a vulnerability. I hope there will be a plan to update the scheduler to exclude this library.

    this is how it looks in go.mod gopkg.in/yaml.v2 v2.4.0 // indirect

  • Add isRunning() function and var on Job

    Add isRunning() function and var on Job

    IsRunning will allow external programs to know when a particular job is running, which may be useful for say graceful shutdown.

    Example Situation: Running scheduler from a console application and when the console application is terminated, say using SIGTERM, it will quit all of the Jobs using the Quit channel, but also try and wait for currently running jobs to finish processing before terminating.

  • Allow for immediate start

    Allow for immediate start

    I would like to see an option to start a job immediately and then run afterword at a scheduled time.

    Example: Run immediately, and thereafter every day at 8:00:00

    scheduler.Every().Day().At("8:00:00").StartImmediately()
    

    Run immediately, and thereafter every other hour

    scheduler.Every(2).Hours().StartImmediately()
    
  • Add support for a .Delay(x) for recurrent jobs

    Add support for a .Delay(x) for recurrent jobs

    In ocassions we want to add some delay to a recurrent job that is different to the recurrent period itself.

    I add a .Delay() modifier that changes the time for the initial delay. This in incompatible to NotImmediatelly().

    I added here two possible implementation in two different commits:

    • .Delay(10 * time.Second): we pass a time.Duration directly
    • .Delay(10).Seconds(): more complex and magic behaviour, it behaves like Every(x), but nicer to read

    Let me know which one you like the most and I can rebase this PR (or just merge it if you like it :))

  • Schedule by UTC Time

    Schedule by UTC Time

    Daily and weekly scheduling should be done by UTC time. A long running process which uses the scheduler would fail to execute at the correct time when a time change occurred.

  • UTC/standardized time

    UTC/standardized time

    It looks like the specific time functions are triggered using subjective time based on the machine implementing this library. It'd be great if there were a way to specify UTC (more flexible for cloud/server deployments).

    Thanks!

high performance distributed task scheduling system, Support multi protocol scheduling tasks
 high performance distributed task scheduling system, Support multi protocol scheduling tasks

high performance distributed task scheduling system, Support multi protocol scheduling tasks

Dec 2, 2022
clockwork - Simple and intuitive job scheduling library in Go.
clockwork - Simple and intuitive job scheduling library in Go.

clockwork A simple and intuitive scheduling library in Go. Inspired by python's schedule and ruby's clockwork libraries. Example use package main imp

Jul 27, 2022
goCron: A Golang Job Scheduling Package.

goCron: A Golang Job Scheduling Package.

Jan 9, 2023
A zero-dependencies and lightweight go library for job scheduling

A zero-dependencies and lightweight go library for job scheduling.

Aug 3, 2022
Executes jobs in separate GO routines. Provides Timeout, StartTime controls. Provides Cancel all running job before new job is run.

jobExecutor Library to execute jobs in GO routines. Provides for Job Timeout/Deadline (MaxDuration()) Job Start WallClock control (When()) Add a job b

Jan 10, 2022
Easy and fluent Go cron scheduling

goCron: A Golang Job Scheduling Package. goCron is a Golang job scheduling package which lets you run Go functions periodically at pre-determined inte

Jan 8, 2023
Simple, zero-dependency scheduling library for Go

go-quartz Simple, zero-dependency scheduling library for Go. About Inspired by the Quartz Java scheduler. Library building blocks Job interface. Any t

Dec 30, 2022
Distributed Task Scheduling System|分布式定时任务调度平台
Distributed Task Scheduling System|分布式定时任务调度平台

Crocodile Distributed Task Scheduling System English | 中文 Introduction A distributed task scheduling system based on Golang that supports http request

Jan 5, 2023
nano-gpu-scheduler is a Kubernetes scheduler extender for GPU resources scheduling.
nano-gpu-scheduler is a Kubernetes scheduler extender for GPU resources scheduling.

Nano GPU Scheduler About This Project With the continuous evolution of cloud native AI scenarios, more and more users run AI tasks on Kubernetes, whic

Dec 29, 2022
K8s cluster simulator for workload scheduling.
K8s cluster simulator for workload scheduling.

Open-Simulator Motivation 概念定义 Open-Simulator 是 K8s 下的仿真调度组件。用户准备一批待创建 Workload 资源,Workload 资源指定好资源配额、绑核规则、亲和性规则、优先级等,通过 Open-Simulator 的仿真调度能力可判断当前集群

Dec 25, 2022
A way of scheduling volcano jobs

JobFlow 背景 volcano Volcano是CNCF 下首个也是唯一的基于Kubernetes的容器批量计算平台,主要用于高性能计算场景。 它提供了Kubernetes目前缺 少的一套机制,这些机制通常是机器学习大数据应用、科学计算、 特效渲染等多种高性能工作负载所需的。 现状:当前vol

Oct 12, 2022
Scheduler - Scheduler package is a zero-dependency scheduling library for Go

Scheduler Scheduler package is a zero-dependency scheduling library for Go Insta

Jan 14, 2022
You had one job, or more then one, which can be done in steps

Leprechaun Leprechaun is tool where you can schedule your recurring tasks to be performed over and over. In Leprechaun tasks are recipes, lets observe

Nov 23, 2022
A programmable, observable and distributed job orchestration system.
A programmable, observable and distributed job orchestration system.

?? Overview Odin is a programmable, observable and distributed job orchestration system which allows for the scheduling, management and unattended bac

Dec 21, 2022
Machinery is an asynchronous task queue/job queue based on distributed message passing.
Machinery is an asynchronous task queue/job queue based on distributed message passing.

Machinery Machinery is an asynchronous task queue/job queue based on distributed message passing. V2 Experiment First Steps Configuration Lock Broker

Dec 24, 2022
Run Jobs on a schedule, supports fixed interval, timely, and cron-expression timers; Instrument your processes and expose metrics for each job.

A simple process manager that allows you to specify a Schedule that execute a Job based on a Timer. Schedule manage the state of this job allowing you to start/stop/restart in concurrent safe way. Schedule also instrument this Job and gather metrics and optionally expose them via uber-go/tally scope.

Dec 8, 2022
Simple job queues for Go backed by Redis
Simple job queues for Go backed by Redis

bokchoy Introduction Bokchoy is a simple Go library for queueing tasks and processing them in the background with workers. It should be integrated in

Dec 13, 2022
golang job dispatcher
golang job dispatcher

go-gearman The shardingkey is hashed to the same queue, each of which is bound to a worker.

Dec 28, 2022
Job worker service that provides an API to run arbitrary Linux processes.
Job worker service that provides an API to run arbitrary Linux processes.

Job Scheduler Summary Prototype job worker service that provides an API to run arbitrary Linux processes. Overview Library The library (Worker) is a r

May 26, 2022