
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@lark-apaas/nestjs-trigger
Advanced tools
为 NestJS 应用提供声明式自动化任务注册与执行能力的核心模块。
基于 TriggerClient 实现,提供 @Automation/@BindTrigger 装饰器、自动发现机制、REST 触发接口,以及与 trigger-server 的完整集成。
@Automation 和 @BindTrigger 装饰器定义自动化任务npm install @lark-apaas/nestjs-trigger
# 或
yarn add @lark-apaas/nestjs-trigger
在根模块中导入 AutomationModule:
import { Module } from '@nestjs/common';
import { AutomationModule } from '@lark-apaas/nestjs-trigger';
@Module({
imports: [AutomationModule.forRoot()],
})
export class AppModule {}
使用 @Automation() 和 @BindTrigger() 装饰器定义任务:
// xxx.automation.ts
import { Automation, BindTrigger } from '@lark-apaas/nestjs-trigger';
@Automation()
export class MyAutomationService {
/**
* 简单的问候任务
*/
@BindTrigger('task-hello', {
actionName: 'HelloTask',
actionDesc: 'Print hello message'
})
async hello(name: string) {
return `Hello, ${name}!`;
}
/**
* 定时任务示例 - 每周五15:00执行
*/
@BindTrigger('cron1[0 15 * * Fri]', {
actionName: 'SendWeeklyEmail',
actionDesc: '每周五15:00发送邮件'
})
async sendWeeklyEmail() {
// 每周五发送邮件逻辑
return { success: true, sentAt: new Date() };
}
}
在 XXXModule 中导入 MyAutomationService:
import { Module } from '@nestjs/common';
import { XController } from './x.controller';
import { MyAutomationService } from './my.automation';
@Module({
controllers: [XController],
providers: [MyAutomationService],
})
export class XModule {}
类装饰器,标记一个类为自动化任务控制器。
@Automation()
@Injectable()
export class EmailAutomation {
// 任务方法定义
}
方法装饰器,将方法绑定到指定的 trigger。
参数:
@BindTrigger(trigger: string, options?: {
actionName?: string; // 任务名称
actionDesc?: string; // 任务描述
})
使用示例:
@Automation()
export class NotificationAutomation {
@BindTrigger('cron1[0 15 * * Fri]', {
actionName: 'SendWelcomeEmail',
actionDesc: '每周五15:00发送欢迎邮件'
})
async sendWelcomeEmail(userId: string, email: string) {
// 发送欢迎邮件逻辑
return { success: true, userId };
}
@BindTrigger('process-payment', {
actionName: 'ProcessPayment',
actionDesc: 'Process user payment'
})
async processPayment(orderId: string, amount: number) {
// 处理支付逻辑
return { success: true, orderId, amount };
}
}
重要特性:
提供 REST API 接口,用于接收 trigger-server 的请求。
接口详情:
POST /innerapi/automation/invoke
请求体:
export interface TriggerExecutionDto {
trigger?: string;
triggerID?: string;
triggerType?: string; // cron
instanceID?: string;
startAt?: number;
parameter?: string;
}
响应:
{
"code": 200,
"message": ""
}
状态码说明:
200: 接收成功,异步执行400: 缺少必填字段404: triggerID 未注册500: 内部错误Trigger Server → HTTP POST /innerapi/automation/invoke
↓
AutomationController
↓
AutomationService.executeAction()
↓
TriggerClient.executeAction()
↓
实际任务方法执行
↓
TriggerClient.report() → 观测系统
# 安装依赖
yarn install
# 构建
yarn build
# 获取调试列表
curl -X GET /dev/logs/trace/trigger/list?trigger=xx&triggerID=xx
# 获取调试详情
curl -X GET /dev/logs/trace/trigger/:instanceID
MIT
FAQs
NestJS Automation Task System with Trigger Client
We found that @lark-apaas/nestjs-trigger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.