before_perform, after_perform, before_enqueue, and after_enqueuefunctions of Resque plugins through preProcessor, postProcessor, preEnqueue, and postEnqueue methods. Each middleware requires a name and at least one function. In addition, a middleware can be global, in which case it also requires a priority.preProcessor, you can access the original task params through this.args[0].postProcessor, you can access the task result at this.worker.result.preEnqueue and postEnqueue you can access the task params through this.args[0]. - If you wish to prevent a task from being enqueued using the preEnqueue middleware you must explicitly set the toRun value to false in the callback. Because the task middleware is executed by Resque this is an instance of a Resque Worker and contains a number of other elements which may be useful in a middleware.'use strict'; module.exports = { loadPriority: 1000, initialize: function(api, next){ api.taskTimer = { middleware: { name: 'timer', global: true, priority: 90, preProcessor: function(next){ var worker = this.worker; worker.start = process.hrtime(); next(); }, postProcessor: function(next){ var worker = this.worker; var elapsed = process.hrtime(worker.start); var seconds = elapsed[0]; var millis = elapsed[1] / 1000000; api.log('Task ' + worker.job.class + ' finished in ' + seconds + ' s and ' + millis + ' ms.', 'info'); next(); }, preEnqueue: function(next){ var params = this.args[0]; //Validate params next(null, true); //callback is in form cb(error, toRun) }, postEnqueue: function(next){ api.log("Task successfully enqueued!"); next(); } } }; api.tasks.addMiddleware(api.taskTimer.middleware, function(error){ next(error); }); } };
`actionhero generateAction --name=[name]` -> `actionhero generate action --name=[name]`
`actionhero generateInitializer --name=[name]` -> `actionhero generate initializer --name=[name]`
`actionhero generateServer --name=[name]` -> `actionhero generate server --name=[name]`
`actionhero generateTask --name=[name]` -> `actionhero generate task --name=[name]`
--startPriority, --stopPriority and --loadPrioritydebug status to quiet down ActionHero when starting up.