1.2.2 • Published 10 years ago
hapi-time v1.2.2
Hapi-Time
Hapi-Time is a job scheduling plugin for Hapi based on Agenda.
Installation
npm install --save hapi-timeExamples
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 intervalwhich can be a string such as3 minutes. - By default it is
30 seconds
maxConcurrency
- An optional
numberwhich specifies the max number of jobs that can be running at any given moment. - By default it is
20.
defaultConcurrency
- An optional
numberwhich specifies the default number of a specific job that can be running at any given moment. - By default it is
5.
lockLimit
- An optional
numberwhich specifies the max number jobs that can be locked at any given moment. - By default it is
0for no max.
defaultLockLimit
- An optional
numberwhich specifies the default number of a specific job that can be locked at any given moment. - By default it is
0for no max.
defaultLockLifetime
- an optional
numberwhich specifies the default lock lifetime in milliseconds. - By default it is 10 minutes. This can be overridden by specifying the
lockLifetimeoption 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.
datais an optional argument that will be passed to the processing function underjob.attrs.data.optionsis an optional argument. Right now we support just thetimezoneoption
schedule
Schedules a job to run name once at a given time.
whencan be aDateor aStringsuch astomorrow at 5pm.datais an optional argument that will be passed to the processing function underjob.attrs.data.