Add timeout to tpds worker

This commit is contained in:
James Allen 2014-03-25 22:28:39 +00:00
parent 8146dd7ce9
commit 1ec8bdcaea

View file

@ -33,12 +33,20 @@ processingFuncs =
else else
callback() callback()
pipeStreamFrom: (options, callback)-> pipeStreamFrom: (options, _callback)->
callback = (args...) ->
_callback(args...)
_callback = () ->
if options.filePath == "/droppy/main.tex" if options.filePath == "/droppy/main.tex"
request options.streamOrigin, (err,res, body)-> request options.streamOrigin, (err,res, body)->
logger.log options:options, body:body logger.log options:options, body:body
origin = request(options.streamOrigin) origin = request(options.streamOrigin)
cancelled = false
origin.on 'response', (res) -> origin.on 'response', (res) ->
return if cancelled
if 200 <= res.statusCode < 300 if 200 <= res.statusCode < 300
dest = request(options) dest = request(options)
origin.pipe(dest) origin.pipe(dest)
@ -54,9 +62,17 @@ processingFuncs =
callback(error) callback(error)
origin.on 'error', (err)-> origin.on 'error', (err)->
return if cancelled
logger.error err:err, options:options, "something went wrong in pipeStreamFrom origin" logger.error err:err, options:options, "something went wrong in pipeStreamFrom origin"
callback(err) callback(err)
setTimeout () ->
cancelled = true
error = new Error("timeout")
logger.error err: error, options: options, "timeout"
callback(error)
, 5000
workerRegistration = (groupKey, method, options, callback)-> workerRegistration = (groupKey, method, options, callback)->