Hot Sauce
Couchbase Backed Job Scheduling Management API
Installation
npm install hot-sauce
Testing
npm run test
Code Coverage
Code Coverage provided by Istanbul with hooks for coveralls. To see coverage report run
npm run cover
Usage - built-in start/stop methods
This module can be incorporated into an existing application with applicable start/stop commands
var HotSauce = ; var config = port: 3000 couchbase: cluster: 'http://couchbase.host:8091' bucket: name: 'bucket_name' password: 'p@$$w0rd' logger: console: enabled: true options: level: 'debug' file: enabled: false options: level: 'debug' filename: "hot-sauce.log" ; var hotSauce = config; hotSaucestart;
Usage - subapp in existing app
This module can be incorporated into an existing application as a sub-app
var HotSauce = ; var config = port: 3000 couchbase: cluster: 'http://couchbase.host:8091' bucket: name: 'bucket_name' password: 'p@$$w0rd' logger: console: enabled: true options: level: 'debug' file: enabled: false options: level: 'debug' filename: "hot-sauce.log" ; var hotSauce = config; var app = ;//require an apiKey on all routesappall'*' { ifreqqueryapiKey ; else resstatus400; }; //mount the hot sauce app at /api/app; //start servervar server = http;server;
Configuration
{
port: 3000, //port for server to listen on
couchbase: {
cluster: ['http://couchbase.host:8091'], //array of cochbase cluster nodes
bucket: {
name: 'bucket_name', //bucket to use for storage
password: 'p@$$w0rd'
}
},
logger: {
console: {enabled: true, options: {level: 'debug'}},
file: {enabled: false, options: {level: 'debug', filename: "hot-sauce.log"}}
}
};
Couchbase Configuration
The application requires the existence of 2 views in the bucket
GetAllJobs
{ ;}
GetJobIfAvailable
{ ifdocisActive === null || docisActive === undefined || docisActive === true ifdoclocking && doclockinglocked != true ifdocschedule && docschedulefuture_instanceslength > 0 //only find unlocked jobs var instances = docschedulefuture_instances; forvar i=0; i<instanceslength; i++ var key = ; ; }
GetJobsMaintenance
{ var key = ; key; key; ;}
Routes
- GET
/jobs
Index of all jobs stored in couchbase ** Example Response
"id": "52" "name": "job" "code": "code_52" "description": "desc" "jobData": {} "isActive": true "schedule": "expirationThreshold": 20000 "cron": "*/12 52 * * * *" "future_instances": "2015-08-03T19:52:00.000Z" "2015-08-03T19:52:12.000Z" "2015-08-03T19:52:24.000Z" "2015-08-03T19:52:36.000Z" "2015-08-03T19:52:48.000Z" "locking": {} "lastModified": "2015-08-03T19:06:55.502Z"
-
GET
/jobs/:id
Detail on specific job -
GET
/jobs/available?codes=code1,code2,code3&caller=someone
Given input codes, get & lock an available job bysomeone
. Margin of error for the query is 5 seconds i.e it is feasible to get a job scheduled to run upto 5 seconds in the future. -
GET
/jobs/:id/unlock?caller=someone
Unlocks a locked job -
POST
/jobs
Create/Upload a job ** Example POST request
"id": "52" "name": "job" "isActive": false "code": "every52nd" "description": "desc" "jobData": {} "schedule": "expirationThreshold": 20000 "cron": "*/12 52 * * * *" "locking": {}