/itsup

Simple Cronjob Server written in Node.js, with RESTful API endpoints to get stats and add new cronjobs

Primary LanguageJavaScript

It's up!

Simple server to check if endpoints are up and running.

Requirements

  • Node.js 16+
  • Docker

Setup

Install dependencies

Install the node dependencies:

npm install

Create .env

Create a .env file, you can simply copy the .env.sample one, and default values will work with the configuration set in docker-compose.yml, but if you need to use a separate MariaDB instance, you will need to change that accordingly.

Create configuration

Set the list of endpoints to check by creating a jobs.json, and creating an jobs array, and each record should have the following object:

{
  "url": "https://microsoft.com/",
  "method": "HEAD",
  "cron": "*/1 * * * * *",
  "name": "microsoft-homepage"
}

The properties are the following:

  • url The http request to test
  • method The http method for the request
  • cron A cronjob string, more info can be found here
  • key A urlencoded string to use as a Key to identify the request

A full sample can be seen here:

{
  "jobs": [
    {
      "url": "https://microsoft.com/",
      "method": "HEAD",
      "cron": "*/1 * * * * *",
      "name": "microsoft-homepage"
    },
    {
      "url": "https://google.com/",
      "method": "GET",
      "cron": "*/5 * * * * *",
      "name": "google-homepage"
    }
  ]
}

Run

Run MariaDB with Docker

Run MariaDB with Docker by running:

docker-compose up -d

Create the database

To create the necessary tables, please run the migrations script:

npm run create:db

Run the server

To start it in development mode please run:

npm run dev

To start it a production node process:

npm start

Update the database

You can run migrations via an npm script to keep your db up to date, just run the following:

npm run update:db

Endpoints

Get list of jobs with latest status

GET /jobs/status - Get the list of all the jobs with the most recent status

Get logs of all jobs

GET /jobs/logs - Get the list of all the records for all jobs

Params:

  • limit - Set the limit of records, defaults to 100
  • offset - Set the offset of records, defaults to 0

Create a new job

POST /jobs - Create a new job in the database and add the related cronjob to the queue

Params:

  • name - Name, or Key, to use to identify the job
  • cron - A cronjob string that can be generated here.
  • method - The http method to use for the request
  • url - The url to test

Example:

// POST /jobs
{
    "name": "dev-to",
    "cron": "*/5 * * * * *",
    "method": "GET",
    "url": "https://dev.to"
}

Update an existing job

PATCH /jobs/:id - Update an existing job in the database and updates the related cronjob to the queue

Params:

  • id - The ID of the job
  • name - Name, or Key, to use to identify the job
  • cron - A cronjob string that can be generated here.
  • method - The http method to use for the request
  • url - The url to test

Example:

// PATCH /jobs/1
{
    "name": "dev-to",
    "cron": "*/5 * * * * *",
    "method": "GET",
    "url": "https://dev.to"
}

Update an existing job

DELETE /jobs/:id - Delete an existing job in the database and removes the related cronjob from the queue

Params:

  • id - The ID of the job

Roadmap

  • Create basic endpoints for CRUD operations
  • Create CLI to handle installation/migrations
  • Create UI to see logs

Resources