1.2.2 • Published 8 years ago

hapi-time v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

Hapi-Time

npm version Build Status Dependencies Status DevDependencies Status Known Vulnerabilities Coverage Status

Hapi-Time is a job scheduling plugin for Hapi based on Agenda.

Installation

npm install --save hapi-time

Examples

const HapiTime = require('hapi-time');

server.register({
    register: HapiTime,
    options: {
        mongoUri: 'localhost:27017/schedule_jobs_test',
        jobs: __dirname + '/jobs',
        every: {
            '10 seconds': 'say-hello'
        },
        schedule: {
            'every day at 3am': 'i-am-your-father'
        }
    }
}, (err) => {
    if (!err) {
        // do something!
    }
});
const HapiTime = require('hapi-time');

server.register({
    register: HapiTime,
    options: {
        mongoUri: 'localhost:27017/schedule_jobs_test',
        jobs: __dirname + '/jobs',
        every: {
            '30 minutes': [ 'say-hello', 'say-bye' ]
        },
        schedule: {
            'every day at 3am': [
                {
                    'say-hello' : {
                        data: {
                            userId: 1
                        }
                    }
                },
                {
                    'say-bye': {
                        data: {
                            userId: 2
                        }
                    }
                }
            ]
        }
    }
}, (err) => {
    if (!err) {
        // do something!
    }
});

Plugin options

mongoUri

MongoDB connection string (example 'localhost:27017/schedule_jobs_test_db'). Check at the official MongoDB documentation

  • A required string

jobs

Path on the file system to the directory that includes the file jobs.

  • A required string
  • To get an idea about how the jobs are, check this directory

processEvery

  • An optional string interval which can be a string such as 3 minutes.
  • By default it is 30 seconds

maxConcurrency

  • An optional number which specifies the max number of jobs that can be running at any given moment.
  • By default it is 20.

defaultConcurrency

  • An optional number which specifies the default number of a specific job that can be running at any given moment.
  • By default it is 5.

lockLimit

  • An optional number which specifies the max number jobs that can be locked at any given moment.
  • By default it is 0 for no max.

defaultLockLimit

  • An optional number which specifies the default number of a specific job that can be locked at any given moment.
  • By default it is 0 for no max.

defaultLockLifetime

  • an optional number which specifies the default lock lifetime in milliseconds.
  • By default it is 10 minutes. This can be overridden by specifying the lockLifetime option to a defined job.

every

Runs job name at the given interval. Optionally, data and options can be passed in. The interval can be a human-readable format String, a cron format String, or a Number.

  • data is an optional argument that will be passed to the processing function under job.attrs.data.
  • options is an optional argument. Right now we support just the timezone option

schedule

Schedules a job to run name once at a given time.

  • when can be a Date or a String such as tomorrow at 5pm.
  • data is an optional argument that will be passed to the processing function under job.attrs.data.
1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.0.0

8 years ago