|
|
@ -40,17 +40,29 @@ export async function waitForTask(handle: (task: RPCRequest) => Promise<any>) { |
|
|
|
} |
|
|
|
} |
|
|
|
response({ type: RPCReplyType.Started }); |
|
|
|
response({ type: RPCReplyType.Started }); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
while (true) { |
|
|
|
const request = msgpack.decode(msg.content) as RPCRequest; |
|
|
|
try { |
|
|
|
const result = await handle(request); |
|
|
|
const request = msgpack.decode(msg.content) as RPCRequest; |
|
|
|
response({ type: RPCReplyType.Finished, result: result }); |
|
|
|
const result = await handle(request); |
|
|
|
} catch (err) { |
|
|
|
response({ type: RPCReplyType.Finished, result: result }); |
|
|
|
winston.warn(`Failed to run task ${msg.properties.correlationId}: ${err.toString()}, ${err.stack}`); |
|
|
|
break; |
|
|
|
response({ type: RPCReplyType.Error, error: err.toString() }); |
|
|
|
} catch (err) { |
|
|
|
|
|
|
|
let errorMessage = `Failed to run task ${msg.properties.correlationId}: ${err.toString()}, ${err.stack}`; |
|
|
|
|
|
|
|
winston.warn(errorMessage); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Only retry on 'Error: The child process has exited unexpectedly.'
|
|
|
|
|
|
|
|
if (errorMessage.indexOf('Error: The child process has exited unexpectedly.') !== -1) { |
|
|
|
|
|
|
|
winston.warn('Retrying.'); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response({ type: RPCReplyType.Error, error: err.toString() }); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
channel.ack(msg); |
|
|
|
channel.ack(msg); |
|
|
|
}, { |
|
|
|
}, { |
|
|
|
priority: Cfg.priority |
|
|
|
priority: Cfg.priority |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|