Hapi-Time is a job scheduling plugin for Hapi based on Agenda.
npm install --save hapi-time
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!
}
});
MongoDB connection string (example 'localhost:27017/schedule_jobs_test_db'
). Check at the official MongoDB documentation
- A required string
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
- An optional
string interval
which can be a string such as3 minutes
. - By default it is
30 seconds
- An optional
number
which specifies the max number of jobs that can be running at any given moment. - By default it is
20
.
- 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
.
- 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.
- 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.
- 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.
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 underjob.attrs.data
.options
is an optional argument. Right now we support just thetimezone
option
Schedules a job to run name
once at a given time.
when
can be aDate
or aString
such astomorrow at 5pm
.data
is an optional argument that will be passed to the processing function underjob.attrs.data
.