UNPKG

deepify

Version:
75 lines (57 loc) 1.55 kB
/** * Created by AlexanderC on 8/18/15. */ /* eslint no-undefined: 0 */ 'use strict'; var _Runtime = require('./Runtime'); var _ForksManager = require('./ForksManager'); // avoid process to be killed when some async calls are still active! _ForksManager.ForksManager.registerListener(); let args = process.argv; // @todo: remove this hack args.shift(); args.shift(); let rawRuntime = JSON.parse(args[0]); let runtime = _Runtime.Runtime.createLambda(rawRuntime._lambdaPath, rawRuntime._dynamicContext); runtime.name = rawRuntime._name; /** * * @param {Runtime} runtime * @param {Object} event * @param {Boolean} measureTime */ ((runtime, event, measureTime) => { let contextSent = false; let assureContextNotSent = thing => { if (!contextSent) { contextSent = true; return true; } console.error(`Trying to send ${runtime.name} Lambda context more times!`, thing); return false; }; runtime.succeed = result => { if (assureContextNotSent(result)) { process.send({ state: 'succeed', args: [result] }); } }; runtime.fail = error => { if (assureContextNotSent(error)) { if (typeof error !== 'string') { try { error = JSON.parse(error); } catch (e) { console.debug('Unable to parse error: ', error); } } process.send({ state: 'fail', args: [error] }); } }; runtime.run(event, measureTime); })(runtime, JSON.parse(args[1]), args.length > 2 ? args[2] : undefined);