Job scheduling made easy.

Related tags

scheduler
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
  • Improve the readme example.

    Improve the readme example.

    opened by freshteapot 4
  • utc

    utc

    opened by brandonblock 3
  • how do I config task to run only once

    how do I config task to run only once

    Hi, is it possible to run job only once in the future? example if I want to run task for tomorrow at 10.00..

    opened by goldalworming 2
  • 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
  • Data race in Run method.

    Data race in Run method.

    As suggested in this comment there is a data race when setting and getting isRunning.

    opened by carlescere 1
  • Start and Stop a Job?

    Start and Stop a Job?

    Is there anyway for me to start and stop a job with a different cycle? Or is it possible for me to kill a job?

    opened by pyros2097 1
  • Add

    Add "How it works?" section to README

    It would be nice to have a How it works? section in the README to explain how many goroutines are spawned and how the time remaining is controlled.

    documentation enhancement 
    opened by carlescere 0
  • Support context.Context to permit job cancelation

    Support context.Context to permit job cancelation

    It would be nice to support context.Context such that each job can pass the context on to permit cancellation of long running operations.

    opened by joefitzgerald 0
  • fix memory leak in Run()

    fix memory leak in Run()

    opened by daneshvar 0
  • 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
  • Job specs from external configuration

    Job specs from external configuration

    Hi,

    What if you want to store your task configuration parameters in a database or a yml/ini/js file? How would you map to those functions?

    opened by mkozjak 1
  • 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 pyros2097 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
A persistent and flexible background jobs library for go.

Jobs Development Status Jobs is no longer being actively developed. I will still try my best to respond to issues and pull requests, but in general yo

Alex Browne 482 May 31, 2021
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 5 Jun 2, 2021
Efficient and reliable background processing for Go

CurlyQ CurlyQ provides a simple, easy-to-use interface for performing background processing in Go. It supports scheduled jobs, job deduplication, and

James McMath 112 Apr 25, 2021
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 952 Jul 22, 2021
Chrono is a scheduler library that lets you run your task and code periodically

Chrono is a scheduler library that lets you run your tasks and code periodically. It provides different scheduling functionalities to make it easier t

Procyon 104 Jul 20, 2021
goCron: A Golang Job Scheduling Package.

goCron: A Golang Job Scheduling Package.

辣椒面 2.6k Jul 22, 2021
A lightweight job scheduler based on priority queue with timeout, retry, replica, context cancellation and easy semantics for job chaining. Build for golang web apps.

Table of Contents Introduction What is RIO? Concern An asynchronous job processor Easy management of these goroutines and chaining them Introduction W

Supratim Samanta 36 Jul 7, 2021
Job scheduling made easy.

scheduler Job scheduling made easy. Scheduler allows you to schedule recurrent jobs with an easy-to-read syntax. Inspired by the article Rethinking Cr

Carles Cerezo Guzmán 368 Jul 10, 2021
gron, Cron Jobs in Go.

gron Gron provides a clear syntax for writing and deploying cron jobs. Goals Minimalist APIs for scheduling jobs. Thread safety. Customizable Job Type

roylee0704 863 Jul 20, 2021
Distributed Task Scheduling System|分布式定时任务调度平台

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

labulaka521 591 Jul 18, 2021
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. 145 Jul 10, 2021
A simple job scheduler backed by Postgres.

A simple job scheduler backed by Postgres used in production at https://operand.ai. Setup needs two environment variables, SECRET and ENDPOINT. The se

Morgan Gallant 6 May 31, 2021
Framework for performing work asynchronously, outside of the request flow

JobRunner JobRunner is framework for performing work asynchronously, outside of the request flow. It comes with cron to schedule and queue job functio

Bam Azizi 861 Jul 27, 2021
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 421 Jul 11, 2021