UNPKG

635 BJavaScriptView Raw
1'use strict';
2
3// try to use eggUtils.getCalleeFromStack
4// ignore it if egg-core module not found
5let eggUtils;
6try {
7 eggUtils = require('egg-core').utils;
8 if (!eggUtils) {
9 // try to support egg-core@3
10 eggUtils = require('egg-core/lib/utils');
11 }
12} catch (_) {
13 // ignore eggUtils
14}
15
16module.exports = {
17 runInBackground(scope) {
18 /* istanbul ignore next */
19 const taskName = scope._name || scope.name || (eggUtils && eggUtils.getCalleeFromStack(true));
20 if (taskName) {
21 scope._name = taskName;
22 }
23
24 const promise = this._runInBackground(scope);
25 this.app._backgroundTasks.push(promise);
26 },
27};