Giter VIP home page Giter VIP logo

scheduler-1's Introduction

Deploy on Railway

A simple job scheduler backed by Postgres used in production at https://operand.ai. Setup needs two environment variables, SECRET and ENDPOINT. The secret is attached to incoming/outgoing requests within the Scheduler-Secret HTTP header, and is used both by the scheduler to verify that incoming request is legit, as well as the end-application to verify the request is coming from the scheduler. The endpoint is simply the URL to send HTTP requests to.

This scheduler also has support for CRON-type expressions. This allows the application to specify a set of id's to run on a schedule. You should probably just make a request on application start with all the IDs and the relevant CRON expressions. This will tear-down the world and re-start the CRON server with the new values. This is how you should do it, especially in auto-deployment environments. When a cron job fires, the application will get a POST with the "cron_id" set. You should check for this in the message and respond appropriately.

This is used in production at Operand.

Example Usage:

Scheduling a Job

POST https://scheduler.yourcompany.com/insert
Headers: Scheduler-Secret=XXXXXX

{
    "timestamp": "2021-04-15T14:17:00-07:00",
    "body": {
        "foo": "bar"
    }
}

Response:
{"id":"cknjdu2k300153zugmucamxxo"}

Cancelling a Scheduled Job (note: if the job doesn't exist, this will fail silently.)

POST https://scheduler.yourcompany.com/delete
Headers: Scheduler-Secret=XXXXXX

{
    "id":"cknjdu2k300153zugmucamxxo"
}

Response: None

Configuring CRON Jobs

POST https://scheduler.yourcompany.com/cron
Headers: Scheduler-Secret=XXXXXX

{
    "jobs":[
        {
            "id":"hello_world",
            "spec": "30 * * * * *"
        },
        {
            "id":"hello_world_2",
            "spec": "0 * * * * *"
        }
    ]
}

Response: None

When a scheduled job, or a CRON job fires, your application (located at endpoint) will get the following message in a POST:

{
  "id": "<job id>", // will be empty if cron_id non-empty
  "cron_id": "<cron id>", // will be empty if id non-empty
  "body": { // Omitted for CRON jobs.
    ... // Your stuff here
  }
}

And that's it! Feel free to file issues or do pull requests.

scheduler-1's People

Contributors

morgangallant avatar

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.