Popularity
6.3
Growing
Activity
0.0
Stable
330
15
42

Programming language: Go
Tags: Utilities    
Latest version: v0.1

scheduler alternatives and similar packages

Based on the "Utilities" category

Do you think we are missing an alternative of scheduler or a related project?

Add another 'Utilities' Package

README

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.


*Note that all licence references and agreements mentioned in the scheduler README section above are relevant to that project's source code only.