Skip to content

Commit 831f76f

Browse files
committed
[api] Worker spawn command
1 parent 768f074 commit 831f76f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

lib/forever/worker.js

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ Worker.prototype.start = function (cb) {
4444
socket.data(['data'], function () {
4545
socket.send(['data'], self.monitor.data);
4646
});
47+
48+
socket.data(['spawn'], function (data) {
49+
if (!data.script) {
50+
return socket.send(['spawn', 'error'], { error: new Error('No script given') });
51+
}
52+
53+
if (this.monitor) {
54+
return socket.send(['spawn', 'error'], { error: new Error("Already running") });
55+
}
56+
57+
var monitor = new (forever.Monitor)(data.script, data.options);
58+
monitor.start();
59+
60+
monitor.on('start', function () {
61+
socket.send(['spawn', 'start']);
62+
});
63+
});
4764
});
4865

4966
findSocket(self.sockPath, function (err, sock) {

0 commit comments

Comments
 (0)