dalga

package module
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2020 License: MIT Imports: 13 Imported by: 0

README

Dalga

Build Status

Dalga is a job scheduler.

  • Can schedule periodic or one-off jobs.
  • Stores jobs in a MySQL table.
  • Has an HTTP interface for scheduling and cancelling jobs.
  • Makes a POST request to the endpoint defined in config on the job's execution time.
  • Multiple instances can be run for scaling out.

Install

$ go get github.com/cenkalti/dalga/v2/cmd/dalga

Usage

Example config file is in the repository.

To create the table for storing jobs:

$ dalga -config dalga.ini -create-table

Then, run the server:

$ dalga -config dalga.ini

Schedule a new job to run every 60 seconds:

$ curl -i -X PUT 'http://127.0.0.1:34006/jobs/check_feed/1234?interval=60'
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Date: Tue, 11 Nov 2014 22:10:40 GMT
Content-Length: 83

{"path":"check_feed","body":"1234","interval":60,"next_run":"2014-11-11T22:11:40Z"}

PUT always returns 201. If there is an existing job with path and body, it will be rescheduled.

There are 4 options that you can pass to Schedule but not every combination is valid:

Param Description Type Example
interval Run job at intervals in seconds Integer 60
first-run Do not run job until this time RFC3339 Timestamp 1985-04-12T23:20:50.52Z
one-off Run job only once Boolean true, false, 1, 0
immediate Run job immediately as it is scheduled Boolean true, false, 1, 0

60 seconds later, Dalga makes a POST to your endpoint defined in config:

Path: <config.baseurl>/<job.path>
Body: <job.body>

The endpoint must return 200 if the job is successful.

The endpoint may return 204 if job is invalid. In this case Dalga will remove the job from the table.

Anything other than 200 or 204 makes Dalga to retry the job indefinitely with an exponential backoff.

Get the status of a job:

$ curl -i -X GET 'http://127.0.0.1:34006/jobs/check_feed/1234'
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Tue, 11 Nov 2014 22:12:21 GMT
Content-Length: 83

{"path":"check_feed","body":"1234","interval":60,"next_run":"2014-11-11T22:12:41Z"}

GET may return 404 if job is not found.

Cancel previously scheduled job:

$ curl -i -X DELETE 'http://127.0.0.1:34006/jobs/check_feed/1234'
HTTP/1.1 204 No Content
Date: Tue, 11 Nov 2014 22:13:35 GMT

Documentation

Index

Constants

View Source
const Version = "2.0.0"

Variables

View Source
var DefaultConfig = Config{
	Jobs: jobsConfig{
		RetryInterval: 60,
	},
	MySQL: mysqlConfig{
		Host:         "127.0.0.1",
		Port:         3306,
		DB:           "test",
		Table:        "dalga",
		User:         "root",
		Password:     "",
		MaxOpenConns: 50,
	},
	Listen: listenConfig{
		Host: "127.0.0.1",
		Port: 34006,
	},
	Endpoint: endpointConfig{
		BaseURL: "http://127.0.0.1:5000/",
		Timeout: 10,
	},
}

Functions

This section is empty.

Types

type Config

type Config struct {
	Jobs     jobsConfig
	MySQL    mysqlConfig
	Listen   listenConfig
	Endpoint endpointConfig
}

func (*Config) LoadFromFile

func (c *Config) LoadFromFile(filename string) error

type Dalga

type Dalga struct {
	Jobs *jobmanager.JobManager
	// contains filtered or unexported fields
}

Dalga is a job scheduler.

func New

func New(config Config) (*Dalga, error)

New returns a new Dalga instance. Close must be called when disposing the object.

func (*Dalga) Close

func (d *Dalga) Close()

Close database connections and HTTP listener.

func (*Dalga) CreateTable

func (d *Dalga) CreateTable() error

CreateTable creates the table for storing jobs on database.

func (*Dalga) NotifyDone

func (d *Dalga) NotifyDone() chan struct{}

NotifyDone returns a channel that will be closed when Run method returns.

func (*Dalga) Run

func (d *Dalga) Run(ctx context.Context)

Run Dalga. This function is blocking.

Directories

Path Synopsis
cmd
internal
log

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL