Skip to content

Commit c380a9f

Browse files
committed
Added a manager script to run all three scripts and keep them alive.
1 parent e3d7a8e commit c380a9f

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

scripts/manager.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
var path = require( "path" ),
2+
spawn = require( "child_process" ).spawn;
3+
4+
function Process( script ) {
5+
this.args = [].slice.call( arguments );
6+
this.args[ 0 ] = path.join( __dirname, script );
7+
this.start();
8+
Process.list.push( this );
9+
}
10+
11+
Process.list = [];
12+
13+
Process.prototype.respawn = true;
14+
15+
Process.prototype.start = function() {
16+
this.child = spawn( "node", this.args );
17+
this.child.on( "exit", this.onExit.bind( this ) );
18+
};
19+
20+
Process.prototype.onExit = function( code ) {
21+
if ( code !== 0 && this.respawn ) {
22+
this.start();
23+
}
24+
};
25+
26+
new Process( "update-server.js", "--console" );
27+
new Process( "wordpress-update.js", "--console" );
28+
new Process( "retry.js", "--console" );
29+
30+
// Let SIGINT pass through to spawned processes. When all children exit,
31+
// the manager will end on its own.
32+
process.on( "SIGINT", function() {
33+
Process.list.forEach(function( process ) {
34+
process.respawn = false;
35+
});
36+
});

scripts/retry.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ actions.processMeta = function( repoId, fn ) {
3636
hook.processMeta( repo, fn );
3737
};
3838

39-
function processFailures( fn ) {
39+
var processFailures = function( fn ) {
4040
Step(
4141
function() {
4242
retry.getFailure( this );
@@ -74,14 +74,21 @@ function processFailures( fn ) {
7474

7575
function( error ) {
7676
if ( error ) {
77-
console.log( error.stack );
77+
return fn( error );
7878
}
7979

8080
processFailures( fn );
8181
}
8282
);
83-
}
83+
};
8484

8585
processFailures(function( error ) {
8686
logger.error( "Error during retry: " + error.stack );
8787
});
88+
89+
// Let the current retry finish, then stop processing and exit
90+
process.on( "SIGINT", function() {
91+
processFailures = function( fn ) {
92+
fn( null );
93+
};
94+
});

scripts/wordpress-update.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ function processActions( fn ) {
199199
);
200200
}
201201

202-
function processActionsSince( actionId, fn ) {
202+
var processActionsSince = function( actionId, fn ) {
203203
Step(
204204
function() {
205205
processNextAction( actionId, this );
@@ -230,7 +230,7 @@ function processActionsSince( actionId, fn ) {
230230
processActionsSince( action.id, fn );
231231
}
232232
);
233-
}
233+
};
234234

235235
function processNextAction( actionId, fn ) {
236236
Step(
@@ -268,3 +268,10 @@ function processNextAction( actionId, fn ) {
268268
processActions(function( error ) {
269269
logger.error( "Error updating WordPress: " + error.stack );
270270
});
271+
272+
// Let the current action finish, then stop processing and exit
273+
process.on( "SIGINT", function() {
274+
processActionsSince = function( actionId, fn ) {
275+
fn( null );
276+
};
277+
});

0 commit comments

Comments
 (0)