@eggjs/tegg-background-task v3.39.3
@eggjs/tegg-background-task
install
npm i --save @eggjs/tegg-background-task
Usage
import { BackgroundTaskHelper } from '@eggjs/tegg-background-task';
@ContextProto()
export default class BackgroundService {
@Inject()
private readonly backgroundTaskHelper:BackgroundTaskHelper
async backgroundAdd() {
this.backgroundTaskHelper.run(async () => {
// do the background task
});
}
}
Background
tegg release the request context after request is done. So use the process.nextTick
, setTimeout
, setInterval
in request is not safe.
Please use the backgroundTaskHelper
, the release process will wait all the background tasks are done.
Timeout
The release process will wait tasks done, but not forever. The default timeout is 5s, if task will cost more than 5s, two ways to resolve
- use the
SingletonProto
to do the work,SingletonProto
never release - set longer timeout to
backgroundTaskHelper.timeout
24 days ago
23 days ago
23 days ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
5 months ago
9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
10 months ago
8 months ago
8 months ago
9 months ago
10 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
10 months ago
7 months ago
6 months ago
7 months ago
11 months ago
11 months ago
11 months ago
1 year ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago