Skip to content

Commit ef193fa

Browse files
committed
chore(cleanup): Main class
1 parent 67334f0 commit ef193fa

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

classes/BackgroundTasks.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
var Class = require( 'classes' ).Class
2-
, path = require( 'path' )
3-
, async = require( 'async' )
4-
, debug = require( 'debug' )( 'BackgroundTasks');
1+
var Class = require( 'classes' ).Class
2+
, path = require( 'path' )
3+
, async = require( 'async' )
4+
, injector = require( 'injector' )
5+
, redis = require( 'redis' )
6+
, debug = require( 'debug' )( 'BackgroundTasks');
57

68
var BackgroundTasks = Class.extend(
79
{
@@ -24,14 +26,18 @@ var BackgroundTasks = Class.extend(
2426

2527
interval: null,
2628

29+
isMaster: false,
30+
2731
setup: function( config, cluster ) {
2832
debug( 'Setting up...' );
2933

3034
try {
3135
process.on( 'message', this.proxy( 'masterIpcMessage' ) );
32-
this.workers = {};
33-
this.config = config[ 'clever-background-tasks' ];
34-
this.cluster = cluster;
36+
37+
this.workers = {};
38+
this.config = config[ 'clever-background-tasks' ];
39+
this.cluster = cluster;
40+
3541
this.cluster.setupMaster({
3642
exec: path.resolve( path.join( __dirname, '..', 'bin', 'task.js' ) )
3743
});
@@ -115,9 +121,10 @@ var BackgroundTasks = Class.extend(
115121
},
116122

117123
runTaskOnWorker: function( taskName, pid ) {
118-
if ( this.workers[ taskName ][ pid ].task.interval !== false ) {
124+
var task = this.workers[ taskName ][ pid ].task;
125+
if ( task.interval !== false && ( !task.masterOnly || !!task.masterOnly && !!this.isMaster ) ) {
119126
debug( 'Running '+ taskName + '...' );
120-
127+
121128
var worker = this.workers[ taskName ][ pid ];
122129
if ( !!worker.ready && !worker.busy ) {
123130
worker.send( { payload: null } );

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"license": "BSD-2-Clause",
3333
"dependencies": {
3434
"memcached": "~0.2.6",
35-
"redis": "0.10.3",
35+
"redis": "~0.12.1",
3636
"moment": "~2.5.0"
3737
},
3838
"devDependencies": {

0 commit comments

Comments
 (0)