All Projects → antonsamper → hapi-cron

antonsamper / hapi-cron

Licence: BSD-3-Clause License
🕰️ Cron jobs for internal hapi.js routes

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to hapi-cron

cron-command
Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
Stars: ✭ 23 (-43.9%)
Mutual labels:  cron
reports
UI for created and download reports in Laravel
Stars: ✭ 13 (-68.29%)
Mutual labels:  cron
docker-backup-to-s3
Docker container that periodically backups files to Amazon S3 using s3cmd and cron
Stars: ✭ 124 (+202.44%)
Mutual labels:  cron
kitsu-season-trends
🦊 Kitsu seasonal anime trends
Stars: ✭ 13 (-68.29%)
Mutual labels:  cron
mi-cron
📆 A microscopic parser for standard cron expressions.
Stars: ✭ 16 (-60.98%)
Mutual labels:  cron
lambda-cron
LambdaCron - serverless cron tool
Stars: ✭ 22 (-46.34%)
Mutual labels:  cron
asparagus
An easy to use task scheduler for distributed systems
Stars: ✭ 14 (-65.85%)
Mutual labels:  cron
hapi-acl-auth
Authentication provider agnostic authorization plugin for HapiJS
Stars: ✭ 22 (-46.34%)
Mutual labels:  hapi
joi-to-typescript
Convert Joi Schemas to TypeScript interfaces
Stars: ✭ 73 (+78.05%)
Mutual labels:  hapi
hapi-imagemin-proxy
Hapi proxy for serving optimized images
Stars: ✭ 30 (-26.83%)
Mutual labels:  hapi
paydash
Worker payments dashboard for MGNREGA
Stars: ✭ 44 (+7.32%)
Mutual labels:  hapi
discord.emojis
hourly cron scraping emojis table from discord client
Stars: ✭ 17 (-58.54%)
Mutual labels:  cron
cronitor-cli
Command line tools for Cronitor.io
Stars: ✭ 31 (-24.39%)
Mutual labels:  cron
emsm
A lightweight, easy to extend minecraft server manager.
Stars: ✭ 72 (+75.61%)
Mutual labels:  cron
linda
Linda is a simple dispatcher library.
Stars: ✭ 12 (-70.73%)
Mutual labels:  cron
arask
Automatic RAils taSKs.
Stars: ✭ 31 (-24.39%)
Mutual labels:  cron
clockwork
A scheduler process to replace cron.
Stars: ✭ 472 (+1051.22%)
Mutual labels:  cron
hapi-dev-errors
A hapi plugin to return better error details and skip the look at command line to catch the issue.
Stars: ✭ 58 (+41.46%)
Mutual labels:  hapi
php-cron-expr
Ultra lightweight, Dependency free and Super Fast Cron Expression parser for PHP
Stars: ✭ 42 (+2.44%)
Mutual labels:  cron
chronic
A tool that hides output unless the command fails; now in Go!
Stars: ✭ 19 (-53.66%)
Mutual labels:  cron

hapi-cron Build Status Greenkeeper badge

A Hapi plugin to setup cron jobs that will call predefined server routes at specified times.

Requirements

This plugin is compatible with hapi v17+ and requires Node v8+. If you need a version compatible with hapi v16 please install version 0.0.3.

Installation

Add hapi-cron as a dependency to your project:

$ npm install --save hapi-cron

Usage

const Hapi = require('@hapi/hapi');
const HapiCron = require('hapi-cron');

const server = new Hapi.Server();

async function allSystemsGo() {

    try {
        await server.register({
            plugin: HapiCron,
            options: {
                jobs: [{
                    name: 'testcron',
                    time: '*/10 * * * * *',
                    timezone: 'Europe/London',
                    request: {
                        method: 'GET',
                        url: '/test-url'
                    },
                    onComplete: (res) => {
                        console.log(res); // 'hello world'
                    }
                }]
            }
        });

        server.route({
            method: 'GET',
            path: '/test-url',
            handler: function (request, h) {
                return 'hello world'
            }
        });

        await server.start();
    }
    catch (err) {
        console.info('there was an error');
    }
}

allSystemsGo();

Options

  • name - A unique name for the cron job
  • time - A valid cron value. See cron configuration
  • timezone - A valid timezone
  • request - The request object containing the route url path. Other options can also be passed into the request object
    • url - Route path to request
    • method - Request method (defaults to GET) - optional
  • onComplete - A synchronous function to run after the route has been requested. The function will contain the result from the request - optional

Cron configuration

This plugin uses the node-cron module to setup the cron job.

Available cron patterns:

Asterisk. E.g. *
Ranges. E.g. 1-3,5
Steps. E.g. */2

Read up on cron patterns here. Note the examples in the link have five fields, and 1 minute as the finest granularity, but the node cron module allows six fields, with 1 second as the finest granularity.

Cron Ranges

When specifying your cron values you'll need to make sure that your values fall within the ranges. For instance, some cron's use a 0-7 range for the day of week where both 0 and 7 represent Sunday. We do not.

  • Seconds: 0-59
  • Minutes: 0-59
  • Hours: 0-23
  • Day of Month: 1-31
  • Months: 0-11
  • Day of Week: 0-6
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].