/scheduly

⏰ Lightweight NodeJS Webhooks scheduler. ⏰

Primary LanguageJavaScript

Scheduly

Scheduly

Scheduly is a Lightweight NodeJS webhooks scheduler

Prerequisite

Deploy in production

Environment variables

  • MONGO_URL (default: mongodb://localhost/agenda)
  • NODE_ENV (values: production or developpement)
  • IP (default: localhost)
  • PORT (default: 8080)

In production

Build

  • docker build -t scheduly .

Run

  • docker run --rm -ti -p 8080:8080 -v "$PWD":/usr/src/app --net host -e "NODE_ENV=production" scheduly

Full documentation

Table of Contents

Creating Webhooks

Creates a webhooks with the given body.

Required body:

Example

  • POST http://localhost:8080/webhooks
  • Body :
{  
   "url": "http://requestb.in/1nlqxcr1",
   "scheduling": "* * * * *",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 201
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z"
  }
]

Note:
  • If scheduling interval is at the cron format, the webhooks will be executed every scheduling interval.
  • If scheduling inverval is at the human interval format, the webhooks will be executed once at scheduling interval.

Errors

  • POST http://localhost:8080/webhooks
  • Body :
{  
   "url": "http://requestb.in/1nlqxcr1",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 400
{
  'error': {
    message: 'Missing required parameter'
  }
}

  • POST http://localhost:8080/webhooks
  • Body :
{
   "scheduling": "* * * * *",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 400
{
  'error': {
    message: 'Missing required parameter'
  }
}

  • POST http://localhost:8080/webhooks
  • Body :
{
   "url": "http://requestb.in/1nlqxcr1",
   "scheduling": "test",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 400
{
  'error': {
    message: 'test is not a valid time interval !'
  }
}

Updating Webhooks

Updates a given webhooks with the new body.

Required body:

Example

  • PUT http://localhost:8080/webhooks/5730a487a3dc0e13009c0a45
  • Body :
{  
   "url": "http://requestb.in/1nlqxcr1",
   "scheduling": "in 2 minutes",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 200
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z"
  }
]

Note:
  • If scheduling interval is at the cron format, the webhooks will be executed every scheduling interval.
  • If scheduling inverval is at the human interval format, the webhooks will be executed once at scheduling interval.

Errors

  • PUT http://localhost:8080/webhooks/5730a487a3dc0e13009c0a45
  • Body :
{  
   "url": "http://requestb.in/1nlqxcr1",
   "scheduling": "in 2 minutes",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 404
{
  'error': {
    message: 'No webhooks to update'
  }
}

  • PUT http://localhost:8080/webhooks/azerty
  • Body :
{  
   "url": "http://requestb.in/1nlqxcr1",
   "scheduling": "in 2 minutes",
   "body": {  
      "hello":"world"
   }
}
  • Response:
Status: 404
{
  'error': {
    message: 'Invalid webhooks id'
  }
}

Getting Webhooks

Returns webhooks

Example

  • GET http://localhost:8080/webhooks
  • Response:
Status: 200
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  }
]

  • GET http://localhost:8080/webhooks/5730a487a3dc0e13009c0a45
  • Response:
Status: 200
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  }
]

  • GET http://localhost:8080/webhooks?previous_cursor=5730a487a3dc0e13009c0a45&next_cursor=5730a487a3dc0e13009c0a45
  • Response:
Status: 200
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  },
  {
    "id": "5730a487a3dc0e13009c0a46",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  }
]

  • GET http://localhost:8080/webhooks?limit=2
  • Response:
Status: 200
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  },
  {
    "id": "5730a487a3dc0e13009c0a46",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  }
]

Errors

  • GET http://localhost:8080/webhooks/azerty
  • Response:
Status: 404
{
  'error': {
    message: 'Invalid webhooks id'
  }
}

Removing Webhooks

Removes the given webhooks if a query parameter (id) is given or removes all webhooks

Example

  • DELETE http://localhost:8080/webhooks
  • Response:
Status: 200
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z"
  },
  {
    "id": "5730a487a3dc0e13009c0a46",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z",
    "status": "scheduled"
  }
]

  • DELETE http://localhost:8080/webhooks/5730a487a3dc0e13009c0a45
[
  {
    "id": "5730a487a3dc0e13009c0a45",
    "url": "http://requestb.in/1nlqxcr1",
    "body": {
      "hello": "world"
    },
    "lastRunAt": null,
    "lastFinishedAt": null,
    "nextRunAt": "2016-05-09T14:56:00.246Z"
  }
]

Errors

  • DELETE http://localhost:8080/webhooks/5730a487a3dc0e13009c0a45
  • Response:
Status: 404
{
  'error': {
    message: 'No webhooks to remove'
  }
}

  • DELETE http://localhost:8080/webhooks
  • Response:
Status: 404
{
  'error': {
    message: 'No webhooks to remove'
  }
}

  • DELETE http://localhost:8080/azerty
  • Response:
Status: 404
{
  'error': {
    message: 'Invalid webhooks id'
  }
}

Deploy in development

Prerequisite

Environment variables

  • MONGO_URL (default: mongodb://localhost/agenda)
  • NODE_ENV (values: production or developpement)
  • IP (default: localhost)
  • PORT (default: 8080)

NodeJS

Build

  • npm run build

Run

  • mongod (on an other terminal)
  • npm start

Docker

Build

  • docker build -t scheduly .

Install node modules

  • docker run --rm -ti -p 8080:8080 -v "$PWD":/usr/src/app node:onbuild npm install

Run

  • docker run --rm -ti -p 8080:8080 -v "$PWD":/usr/src/app --net host scheduly