The following is an example of a complete runnable daemon.
This daemon is part of the composer test cases that were installed from npm.
Let's go through the different files relating to this daemon:
config.js
"use strict"; var prefix = ''; module.exports = { "type": "daemon", //tells the composer whether this is the config for a service or a daemon "dbs": [ //tells the composer what databases does this service user { prefix: prefix, name: "esClient", es: true }, { prefix: prefix, name: "myDatabase", multitenant: false, mongo: true } ], "esIndexes": { "master": ["test_intersection"], "profile": ["clean"] }, prerequisites: { //requirements for High Availability mode cpu: '', memory: '' }, serviceName: "aggregator", //the name of our daemon serviceGroup: "411AGG", //the name of the daemon group servicePort: 4060, //the port where the daemon will run "errors": {}, //list of errors that can be returned by this daemon "schema": { "buildMasterIndex": { //name of the daemon job "mw": __dirname + "/lib/mw/master.js", //business logic of the job "_apiInfo": { "l": "Build Master Index" } }, "cleanUpProfileIndex": { "mw": __dirname + "/lib/mw/profile.js", "_apiInfo": { "l": "Clean Profile Cities, Features & Categories from Autocomplete Indexes" } }, "buildProfileAccessoriesIndex": { "mw": __dirname + "/lib/mw/profile.js", "_apiInfo": { "l": "Build Profile Categories, Cities, Features and Auto Complete Indexes" } }, "buildProfilecategoryCitiesIndex": { "mw": __dirname + "/lib/mw/profile.js", "_apiInfo": { "l": "Build Profile Category_cities Indexes" } }, "buildProfileIndex": { "mw": __dirname + "/lib/mw/profile.js", "_apiInfo": { "l": "Build Profile Addresses and Autocomplete Indexes" } }, "fullTest": { "mw": __dirname + "/lib/mw/fullRun.js", "_apiInfo": { "l": "Build Both Master and Profile Indexes" } } } };
index.js
"use strict"; var composer = require("soajs.composer"); //require the composer composer.deploy(__dirname + "/../data/daemon.test2.js", function(error){ //call composer.deploy to deploy the service from its config file console.log( (error)? error : "Cart Service started ..."); //optional log message after service is started });
Example of a daemon job:
buildMasterIndex job
"use strict"; module.exports = { "mw": function (soajs, cb) { // Business logic of daemon job goes here console.log("inside daemon mw file...."); return cb(null, true); } };
Add Comment