Job scheduling made easy.

Overview

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.

Issues
  • 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.

    opened by deankarn 1
  • 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 :))

    opened by keymon 3
  • 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.

    opened by he4d 3
  • 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!

    opened by brandonblock 0
  • Adding time.Duration?

    Adding time.Duration?

    How about adding time.Duration parameter to job scheduling scheduler.EveryDuration(time.Duration)? So that it becomes easy for me to wrap it in other funcs? Since right now I need to closure some objects.

    opened by pyrossh 0
Releases(0.1)
Owner
Carles Cerezo Guzmán
I bash my keyboard and hope for the best. Software engineer at @YieldifyLabs
Carles Cerezo Guzmán
high performance distributed task scheduling system, Support multi protocol scheduling tasks

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

null 52 Jun 14, 2022
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

null 27 Mar 3, 2022
goCron: A Golang Job Scheduling Package.

goCron: A Golang Job Scheduling Package.

辣椒面 3k Jul 3, 2022
A zero-dependencies and lightweight go library for job scheduling

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

null 1 Jan 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

Eswaran SK 0 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

Go Co Op 2k Jun 26, 2022
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

Eugene R. 880 Jun 30, 2022
Distributed Task Scheduling System|分布式定时任务调度平台

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

labulaka521 854 Jun 24, 2022
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

Nano GPU 82 Jun 22, 2022
K8s cluster simulator for workload scheduling.

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

Alibaba 140 Jun 28, 2022
A way of scheduling volcano jobs

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

BoCloud 17 May 29, 2022
Scheduler - Scheduler package is a zero-dependency scheduling library for Go

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

Javad Rajabzade 4 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

Strahinja 87 May 17, 2022
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

James McDermott 439 Jun 23, 2022
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

Richard Knop 6.3k Jul 1, 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.

Sherif Abdel-Naby 57 Mar 28, 2022
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

Florent Messa 254 Jun 16, 2022
golang job dispatcher

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

fengyun.rui 17 Apr 4, 2022
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

Renato Guimarães 8 May 26, 2022