标签:pomelo nodejs js server components
beforeStartup(app, cb) before application start components callback Arguments app - application object cb - callback function afterStartup(app, cb) after application start components callback Arguments app - application object cb - callback function beforeShutdown(app, cb) before application stop components callback Arguments app - application object cb - callback function afterStartAll(app) after all applications started callback Arguments app - application object
module.exports.beforeStartup = function(app, cb) { // do some operations before application start up cb(); }; module.exports.afterStartup = function(app, cb) { // do some operations after application start up cb(); }; module.exports.beforeShutdown = function(app, cb) { // do some operations before application shutdown down cb(); }; module.exports.afterStartAll = function(app) { // do some operations after all applications start up };
// components/HelloWorld.js module.exports = function(app, opts) { return new HelloWorld(app, opts); }; var HelloWorld = function(app, opts) { this.app = app; this.interval = opts.interval | DEFAULT_INTERVAL; }; HelloWorld.name = '__HelloWorld__'; HelloWorld.prototype.start = function(cb) { console.log('Hello World Start'); cb(); } HelloWorld.prototype.afterStart = function (cb) { console.log('Hello World afterStart'); cb(); } HelloWorld.prototype.stop = function(force, cb) { console.log('Hello World stop'); cb(); }
var helloWorld = require('./app/components/HelloWorld'); app.configure('production|development', 'master', function() { app.load(helloWorld, {interval: 5000}); });
我这边是在arena服务中加入了lifecycle,同时加了一个组件,过程如下。
标签:pomelo nodejs js server components
原文地址:http://blog.csdn.net/xufeng0991/article/details/46602653