node_task 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/node_task/{index.js → nodeTask.js} +14 -6
- data/lib/node_task/node_task.rb +46 -40
- data/lib/node_task/package.json +2 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 251a401a6d440f9a5fd7399519c12bef82ae32ff
|
4
|
+
data.tar.gz: a159f15a8e6ad3f490b9bfb3fcc3c334170105bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc9a7866fd5eaddafbaec94ed2c7b892c8125a65d086705c18a8584069cbaaa9b6d4022dc221b7793dbac9ce44e68d7f4ba8fb6166cd3a86aef28d6aa7ba76d6
|
7
|
+
data.tar.gz: 8d0b4430317f4af05480160b6270ea48815efa43ff5a1d73759ac54c97f4eacd991a02cafc67898e301eae1c4482ae91e6b6a930ded18fa911da08285e5bb677
|
@@ -3,6 +3,9 @@ var path = require('path')
|
|
3
3
|
var net = require('net')
|
4
4
|
var ndjson = require('ndjson')
|
5
5
|
|
6
|
+
var parentCheckInterval = parseInt(process.env.NODE_TASK_PARENT_CHECK_INTERVAL, 10) || 1000;
|
7
|
+
var parentPid = parseInt(process.env.NODE_TASK_DAEMON_ID, 10);
|
8
|
+
|
6
9
|
var workingDir = path.resolve(process.env.NODE_TASK_CWD || __dirname)
|
7
10
|
var errorLogPath = path.join(workingDir, 'ruby_node_task-error.log')
|
8
11
|
var debugLogPath = path.join(workingDir, 'ruby_node_task-debug.log')
|
@@ -24,6 +27,17 @@ var server = net.createServer(onClientConnect)
|
|
24
27
|
process.on('exit', onExit)
|
25
28
|
process.on('uncaughtException', onUncaughtException)
|
26
29
|
|
30
|
+
setInterval(function() {
|
31
|
+
try {
|
32
|
+
process.kill(parentPid, 0);
|
33
|
+
} catch (err) {
|
34
|
+
if (err.code === 'ESRCH') {
|
35
|
+
logger.debug('parent '+parentPid+' is no longer alive, exiting')
|
36
|
+
process.exit()
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}, parentCheckInterval);
|
40
|
+
|
27
41
|
// the important part
|
28
42
|
function onClientConnect(socket) {
|
29
43
|
logger.debug('client connected')
|
@@ -44,12 +58,6 @@ function onClientConnect(socket) {
|
|
44
58
|
return sendError(new Error('only one task can be run per connection'))
|
45
59
|
}
|
46
60
|
|
47
|
-
if (msg.status) {
|
48
|
-
return server.getConnections(function(err, count) {
|
49
|
-
sendMsg({clients: count-1}) // minus this connection
|
50
|
-
})
|
51
|
-
}
|
52
|
-
|
53
61
|
if (!msg.task) {
|
54
62
|
return sendError(new Error('msg.task not defined'))
|
55
63
|
}
|
data/lib/node_task/node_task.rb
CHANGED
@@ -9,13 +9,18 @@ class NodeTask
|
|
9
9
|
START_MAX_RETRIES = 1
|
10
10
|
|
11
11
|
class Error < StandardError
|
12
|
-
|
13
|
-
|
12
|
+
attr_accessor :js_error
|
13
|
+
|
14
|
+
def initialize(original_js_error)
|
15
|
+
js_error = original_js_error
|
16
|
+
|
14
17
|
super(js_error[:message])
|
15
18
|
end
|
16
19
|
|
17
20
|
def to_s
|
18
|
-
|
21
|
+
super unless js_error
|
22
|
+
|
23
|
+
js_error[:stack] || js_error[:message]
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
@@ -64,7 +69,7 @@ class NodeTask
|
|
64
69
|
end
|
65
70
|
|
66
71
|
def daemon_start_script
|
67
|
-
File.join(gem_dir, '
|
72
|
+
File.join(gem_dir, 'nodeTask.js').to_s
|
68
73
|
end
|
69
74
|
|
70
75
|
# get configured daemon controller for daemon, and start it
|
@@ -155,36 +160,30 @@ class NodeTask
|
|
155
160
|
result
|
156
161
|
end
|
157
162
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
163
|
+
def alive?
|
164
|
+
current_pid = nil
|
165
|
+
alive = false
|
166
|
+
if @controller
|
167
|
+
begin
|
168
|
+
current_pid = @controller.pid
|
169
|
+
rescue Errno::ENOENT
|
170
|
+
end
|
171
|
+
end
|
172
|
+
if current_pid
|
173
|
+
begin
|
174
|
+
Process.getpgid(current_pid)
|
175
|
+
alive = true
|
176
|
+
rescue Errno::ESRCH
|
177
|
+
end
|
178
|
+
end
|
179
|
+
alive
|
165
180
|
end
|
166
181
|
|
167
|
-
# stop the daemon
|
182
|
+
# stop the daemon
|
168
183
|
def release
|
169
|
-
|
170
|
-
# this doesn't really work as intended right now
|
171
|
-
# as no connections are maintained when tasks aren't running
|
172
|
-
return if clients_active > 0
|
173
|
-
rescue Errno::ENOENT => e
|
174
|
-
# socket file probably doesn't exist
|
175
|
-
# maybe we should just return here?
|
176
|
-
end
|
184
|
+
return unless alive?
|
177
185
|
|
178
|
-
|
179
|
-
begin
|
180
|
-
pid = @controller.pid
|
181
|
-
rescue Errno::ENOENT => e
|
182
|
-
# presumably no pid file exists and the daemon is not running
|
183
|
-
logger.debug "daemon already stopped"
|
184
|
-
return
|
185
|
-
end
|
186
|
-
|
187
|
-
logger.debug "stopping daemon #{pid}"
|
186
|
+
logger.debug "stopping daemon #{@controller.pid}"
|
188
187
|
@controller.stop
|
189
188
|
|
190
189
|
begin
|
@@ -194,6 +193,21 @@ class NodeTask
|
|
194
193
|
end
|
195
194
|
end
|
196
195
|
|
196
|
+
def daemon_env
|
197
|
+
{
|
198
|
+
"NODE_TASK_SOCK_PATH" => socket_path,
|
199
|
+
"NODE_TASK_CWD" => working_dir,
|
200
|
+
"NODE_TASK_DAEMON_ID" => daemon_identifier,
|
201
|
+
"NODE_TASK_PARENT_PID" => Process.pid.to_s,
|
202
|
+
"NODE_TASK_PARENT_CHECK_INTERVAL" => parent_check_interval.to_s,
|
203
|
+
"NODE_ENV" => ENV["RACK_ENV"],
|
204
|
+
}
|
205
|
+
end
|
206
|
+
|
207
|
+
def parent_check_interval
|
208
|
+
1000
|
209
|
+
end
|
210
|
+
|
197
211
|
private
|
198
212
|
|
199
213
|
def _make_connection
|
@@ -212,12 +226,11 @@ class NodeTask
|
|
212
226
|
# - some server errors not reported
|
213
227
|
def _make_daemon_controller
|
214
228
|
logger.debug "socket_path #{socket_path}"
|
229
|
+
logger.debug "starting #{node_command} #{daemon_start_script}"
|
215
230
|
|
216
|
-
puts "starting #{node_command} #{daemon_start_script}"
|
217
231
|
controller = DaemonController.new(
|
218
232
|
identifier: daemon_identifier,
|
219
233
|
start_command: "#{node_command} #{daemon_start_script}",
|
220
|
-
# ping_command: [:unix, socket_path],
|
221
234
|
ping_command: Proc.new{
|
222
235
|
begin
|
223
236
|
_make_connection
|
@@ -228,19 +241,12 @@ class NodeTask
|
|
228
241
|
},
|
229
242
|
pid_file: pid_file,
|
230
243
|
log_file: error_log_file,
|
231
|
-
env:
|
232
|
-
"NODE_TASK_SOCK_PATH" => socket_path,
|
233
|
-
"NODE_TASK_CWD" => working_dir,
|
234
|
-
"NODE_TASK_DAEMON_ID" => daemon_identifier,
|
235
|
-
"NODE_ENV" => ENV["RACK_ENV"],
|
236
|
-
},
|
244
|
+
env: daemon_env,
|
237
245
|
log_file_activity_timeout: RESPONSE_TIMEOUT,
|
238
246
|
start_timeout: RESPONSE_TIMEOUT,
|
239
247
|
daemonize_for_me: true,
|
240
248
|
)
|
241
249
|
|
242
|
-
at_exit { release }
|
243
|
-
|
244
250
|
controller
|
245
251
|
end
|
246
252
|
end
|
data/lib/node_task/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: node_task
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Friend
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: daemon_controller
|
@@ -37,7 +37,7 @@ extensions: []
|
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|
39
39
|
- lib/node_task.rb
|
40
|
-
- lib/node_task/
|
40
|
+
- lib/node_task/nodeTask.js
|
41
41
|
- lib/node_task/node_modules/ndjson/cli.js
|
42
42
|
- lib/node_task/node_modules/ndjson/collaborators.md
|
43
43
|
- lib/node_task/node_modules/ndjson/index.js
|