Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
_runInBackground(scope) {
const ctx = this;
const start = Date.now();
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
// use app.toAsyncFunction to support both generator function and async function
return ctx.app.toAsyncFunction(scope)(ctx)
.then(() => {
ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start);
})
.catch(err => {
// background task process log
ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start);
// emit error when promise catch, and set err.runInBackground flag
err.runInBackground = true;
ctx.app.emit('error', err, ctx);
});
},
};
_runInBackground(scope) {
const ctx = this;
const start = Date.now();
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
// use app.toAsyncFunction to support both generator function and async function
return ctx.app.toAsyncFunction(scope)(ctx)
.then(() => {
ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start);
})
.catch(err => {
// background task process log
ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start);
// emit error when promise catch, and set err.runInBackground flag
err.runInBackground = true;
ctx.app.emit('error', err, ctx);
});
},
};
runInBackground(scope) {
// try to use custom function name first
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
scope._name = taskName;
this._runInBackground(scope);
},
runInBackground(scope) {
// try to use custom function name first
/* istanbul ignore next */
const taskName = scope._name || scope.name || eggUtils.getCalleeFromStack(true);
scope._name = taskName;
this._runInBackground(scope);
},
runInBackground(scope) {
const ctx = this.createAnonymousContext();
if (!scope.name) scope._name = eggUtils.getCalleeFromStack(true);
ctx.runInBackground(scope);
}