Skip to content

Cron-like background job runner based on a configuration file

License

Notifications You must be signed in to change notification settings

tiabc/jobsrunner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jobsrunner

Sometimes, there is a need for a cron-like jobs runner which run jobs (commands) and waits until the job finishes before starting it again in some pre-specified interval.

Project status

The tool is under active development, don't use it in production now. The library will be ready for production in the following few days.

Running

Installation is performed via a simple command:

go get github.com/tiabc/jobsrunner/jobsrunner

Now, specify jobs in the config file (see below) and run the application:

$GOPATH/bin/jobsrunner config.json 

After launch, jobsrunner immediately starts all the specified jobs. Information about jobs schedule is not stored anywhere and execution of every job will be triggered upon restart.

Configuration file

Jobs are specified as follows:

{
  "version": 1,
  "jobs": [
    {
      "cmd": "yourapp check-statuses",
      "interval": "5 seconds"
    }
  ]
}

Currently, version must be 1 and the list of jobs consists of two fields:

  1. cmd - a command to run.
  2. interval - time to wait before running the command again. A positive integer and modifier (seconds, minutes, hours and may also be singular) are expected. Bigger intervals are not supported as the current version does not store information about jobs schedule anywhere and triggers their execution on restart.

Using as a library

jobsrunner can also be used as a library, for example:

package main

import (
	"context"
	"log"

	"github.com/tiabc/jobsrunner"
)

func main() {
	r, err := jobsrunner.NewFromFile("your-config.json")
	if err != nil {
		log.Fatal(err)
	}
	
	// The second variable is the cancel function which can finish jobsrunner.
	ctx, _ := context.WithCancel(context.Background())
	
	// This call blocks the execution until the context is cancelled.
	r.Run(ctx)
}

Contributing

Contributions are welcome. Feel free to propose changes, create pull requests or request new functionality.

License

MIT

About

Cron-like background job runner based on a configuration file

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages