单次执行
@midwayjs/one-shot 是一个只提供 Framework 的一次性脚本执行组件,适合用 IoC 容器组织依赖,并在应用内触发一次性的任务逻辑。
相关信息:
| 描述 | |
|---|---|
| 可用于标准项目 | ❌ |
| 可用于 Serverless | ❌ |
| 可用于一体化 | ❌ |
| 包含独立主框架 | ✅ |
| 包含独立日志 | ✅ |
安装依赖
在现有项目中安装 one-shot 组件依赖。
$ npm i @midwayjs/one-shot@4 --save
或者在 package.json 中增加如下依赖后,重新安装。
{
"dependencies": {
"@midwayjs/one-shot": "^4.0.0"
}
}
开启组件
在入口配置中引入组件。
// src/configuration.ts
import { Configuration } from '@midwayjs/core';
import * as oneShot from '@midwayjs/one-shot';
@Configuration({
imports: [oneShot],
})
export class MainConfiguration {}