Code Monkey home page Code Monkey logo

crony's Introduction

Crony ๐Ÿ• 

  • All the flexibility and power of Cron as a Service.
  • Simple REST protocol, integrating with a web application in a easy and straightforward way.
  • No more wasting time building and managing scheduling infrastructure.

Basic Concepts

Crony works by calling back to your application via HTTP GET according to a schedule constructed by you or your application.

Setup

Env vars

export DATASTORE_URL="postgresql://postgres@localhost/crony?sslmode=disable"
export PORT=3000
mkdir -p $GOPATH/src/github.com/rafaeljesus
cd $GOPATH/src/github.com/rafaeljesus
git clone https://github.com/rafaeljesus/crony.git
cd crony
make all

Running server

./dist/crony
# => Starting Crony at port 3000

Authentication

This API does not ship with an authentication layer. You should not expose the API to the Internet. This API should be deployed behind a firewall, only your application servers should be allowed to send requests to the API.

API Endpoints

API Documentation

GET /events

Get a list of available events.

  • Method: GET
  • Endpoint: /events
  • Responses:
    • 200 OK
    [
       {
          "id":1,
          "url":"your-api/job",
          "expression": "0 5 * * * *",
          "status": "active",
          "max_retries": 2,
          "retry_timeout": 3,
          "created_at": "2016-12-10T14:02:37.064641296-02:00",
          "updated_at": "2016-12-10T14:02:37.064641296-02:00"
       }
    ]
    • id is the id of the event.
    • url: is the url callback to called.
    • expression: is cron expression format.
    • status: tell if the event is active or paused.
    • max_retries: the number of attempts to send event.
    • retry_timeout: is the retry timeout.

POST /events

Create a new event.

  • Method: POST

  • Endpoint: /events

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "url":"your-api/job",
      "expression": "0 5 * * * *",
      "status": "active",
      "max_retries": 2,
      "retry_timeout": 3,
    }
  • Responses:

    • 201 Created
    {
      "url":"your-api/job",
      "expression": "0 5 * * * *",
      "status": "active",
      "max_retries": 2,
      "retry_timeout": 3,
      "updated_at": "2016-12-10T14:02:37.064641296-02:00",
      "created_at": "2016-12-10T14:02:37.064641296-02:00"
    }
    • 422 Unprocessable entity:
    {
      "status":"invalid_event",
      "message":"<reason>"
    }
    • 400 Bad Request
    {
      "status":"invalid_json",
      "message":"Cannot decode the given JSON payload"
    }

    Common reasons:

    • the event job already scheduled. The message will be Event already exists
    • the expression must be crontab format.
    • the retry must be between 0 and 10
    • the status must be active or incative

GET /events/:id

Get a specific event.

  • Method: GET
  • Endpoint: /events/:id
  • Responses:
    • 200 OK
    {
      "url":"your-api/job",
      "expression": "0 5 * * * *",
      "status": "active",
      "max_retries": 2,
      "retry_timeout": 3,
      "updated_at": "2016-12-10T14:02:37.064641296-02:00",
      "created_at": "2016-12-10T14:02:37.064641296-02:00"
    }
    • 404 Not Found
    {
      "status":"event_not_found",
      "message":"The event was not found"
    }

DELETE /events/:id

Remove a scheduled event.

  • Method: DELETE
  • Endpoint: /events/:id
  • Responses:
    • 200 OK
    {
      "status":"event_deleted",
      "message":"The event was successfully deleted"
    }
    • 404 Not Found
    {
      "status":"event_not_found",
      "message":"The event was not found"
    }

PATCH /events/:id

Update a event.

  • Method: PATCH

  • Endpoint: /events/:id

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "expression": "0 2 * * * *"
    }
  • Responses:

    • 200 OK
    {
      "url":"your-api/job",
      "expression": "0 2 * * * *",
      "status": "active",
      "max_retries": 2,
      "retry_timeout": 3,
      "updated_at": "2016-12-10T14:02:37.064641296-02:00",
      "created_at": "2016-12-10T14:02:37.064641296-02:00"
    }
    • 404 Not Found
    {
      "status":"event_not_found",
      "message":"The event was not found"
    }
    • 422 Unprocessable entity:
    {
      "status":"invalid_json",
      "message":"Cannot decode the given JSON payload"
    }
    • 400 Bad Request
    {
      "status":"invalid_event",
      "message":"<reason>"
    }

Cron Format

The cron expression format allowed is:

Field name Mandatory? Allowed values Allowed special characters
Seconds Yes 0-59 * / , -
Minutes Yes 0-59 * / , -
Hours Yes 0-23 * / , -
Day of month Yes 1-31 * / , - ?
Month Yes 1-12 or JAN-DEC * / , -
Day of week Yes 0-6 or SUN-SAT * / , - ?
more details about expression format here

Contributing

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Commit your changes (git commit -am 'Add some feature')
  • Push to the branch (git push origin my-new-feature)
  • Create new Pull Request

Badges

CircleCI Go Report Card

crony's People

Contributors

aalvesjr avatar rafaeljesus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

crony's Issues

persistence of events : issues about the default value of deleted_at and the Search function

Thank you for sharing this interesting ideas and project @rafaeljesus.

I noticed a couple of issues in the repository implementation (package repos) :

  • on my local env, when a event is persisted, the value of the deleted_at field is '0001-01-01 00:00:00+00' instead of NULL. This breaks all the searches as GORM appends 'delete_at is NULL' at the where clause. A possible workaround is but the best one is to force the gorm to put a null value
db = db.Unscoped() // all the records included the deleted ones
  • the current code raises a SIGSEGV because of uninitialized pointer. Shouldn't the line 56 ...
	var db *gorm.DB

... be replaced by

	var db *gorm.DB = r.db

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.