@eggjs/tegg-background-task
TypeScript icon, indicating that this package has built-in type declarations

3.39.0 • Public • Published

@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

Package Sidebar

Install

npm i @eggjs/tegg-background-task

Weekly Downloads

585

Version

3.39.0

License

MIT

Unpacked Size

13.7 kB

Total Files

7

Last publish

Collaborators

  • gxkl
  • gemwuu
  • eggjs-admin
  • fengmk2
  • atian25
  • dead_horse
  • wanghx
  • hyj1991
  • killagu
  • coolme200
  • mansonchor.zzw
  • hubcarl