@faapi/faapi 6.5.0 → 6.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -268,6 +268,12 @@ interface TaskWorkerOptions {
268
268
  };
269
269
  /** 单次执行超时(毫秒) */
270
270
  timeoutMs: number;
271
+ /**
272
+ * 取消宽限期(毫秒)——两段式取消第一段发出 abort 信号后等待任务自行退出的
273
+ * 最长时间,超时未退出 `terminate()` 硬杀。来自 task meta `graceMs`,
274
+ * 未声明用 `KILL_GRACE_MS`(5s);`0` 表示不留宽限期(判定取消即硬杀)
275
+ */
276
+ graceMs?: number;
271
277
  /**
272
278
  * 注册表快照(纯数据,postMessage 结构化克隆传入,worker 内重建只读视图注入
273
279
  * taskCtx.registries)——语义层从 `TaskRegistriesView` 生成,缺省为空视图
@@ -275,8 +281,11 @@ interface TaskWorkerOptions {
275
281
  registries?: TaskRegistriesSnapshot;
276
282
  /** 外部取消信号(驱动停机超时 abort)——abort 同样触发两段式取消 */
277
283
  externalSignal?: AbortSignal;
278
- /** 宽限期覆盖(默认 KILL_GRACE_MS)——测试注入短值用,业务不配置 */
279
- killGraceMs?: number;
284
+ /**
285
+ * 进度回调:worker 内 `taskCtx.progress(value)` 的值经 `{ type: 'progress' }`
286
+ * 消息回传宿主(语义层记入 `TaskJob.progress`);不传则进度消息被忽略
287
+ */
288
+ onProgress?: (value: unknown) => void;
280
289
  }
281
290
  declare function runTaskInWorker(options: TaskWorkerOptions): Promise<unknown>;
282
291
 
@@ -397,11 +406,23 @@ interface FaapiTaskMeta {
397
406
  /** 失败重试次数(默认 0——失败即 failed,不重试) */
398
407
  retries?: number;
399
408
  /**
400
- * 单次执行超时(毫秒)。声明后该任务在独立 worker 线程执行,超时两段式取消
401
- * (先 abort 信号宽限 5s,未退出 terminate 硬杀)——判定超时即执行真正终止。
402
- * 未声明走进程内执行(零开销,但卡住时框架只能不再等待)。
409
+ * 单次执行超时(毫秒,最小 60000 即 1 分钟——低于阈值在扫描期报错)。声明后该
410
+ * 任务在独立 worker 线程执行,超时两段式取消(先 abort 信号宽限,未退出
411
+ * terminate 硬杀)——判定超时即执行真正终止。未声明走进程内执行(零开销)。
412
+ *
413
+ * 最小值的理由:声明 timeoutMs 的语义是"这是需要真取消的长任务",一分钟内能
414
+ * 跑完的任务没必要声明超时(走进程内,需要 deadline 自行用 Promise.race 实现);
415
+ * 且超时从派发起算、包含 worker 冷启动(线程创建 + 模块加载),过小的超时会在
416
+ * 任务做任何事之前就被取消。
403
417
  */
404
418
  timeoutMs?: number;
419
+ /**
420
+ * 取消宽限期(毫秒,仅声明 `timeoutMs` 的隔离任务生效):两段式取消第一段
421
+ * 发出 abort 信号后等待任务自行退出的最长时间,超时未退出 `terminate()` 硬杀。
422
+ * 默认 5000(5s);`0` 表示不留宽限期(判定取消即硬杀)。
423
+ * 未声明 `timeoutMs` 的任务无取消流程,本字段被忽略。
424
+ */
425
+ graceMs?: number;
405
426
  /** cron 表达式(croner 语法,支持秒级)——到点自动入队空 payload */
406
427
  cron?: string;
407
428
  }
@@ -417,6 +438,7 @@ interface TaskManifest {
417
438
  concurrency?: number;
418
439
  retries?: number;
419
440
  timeoutMs?: number;
441
+ graceMs?: number;
420
442
  }
421
443
  /**
422
444
  * 运行时任务元数据(faapi-tasks.js 水合到 TaskRegistry 后的形态,产物路径形式)
@@ -429,6 +451,8 @@ interface TaskMetadata {
429
451
  concurrency?: number;
430
452
  retries?: number;
431
453
  timeoutMs?: number;
454
+ /** 取消宽限期(毫秒,仅隔离任务生效),未声明用框架默认 5s */
455
+ graceMs?: number;
432
456
  }
433
457
  /**
434
458
  * 任务记录状态
@@ -451,6 +475,8 @@ interface TaskJob {
451
475
  result?: unknown;
452
476
  /** 错误消息(failed 时) */
453
477
  error?: string;
478
+ /** 最近一次进度上报值(run 内 `taskCtx.progress(value)` 写入;派发时清空上一轮) */
479
+ progress?: unknown;
454
480
  createdAt: number;
455
481
  /** 计划执行时间戳(重试/延迟任务与 createdAt 不同) */
456
482
  runAt?: number;
@@ -488,6 +514,13 @@ interface TaskContext {
488
514
  * 任务内组装 agent 用 `registries.agent.getAgentEntry(name)`(含 filePath/hasRun)。
489
515
  */
490
516
  registries: TaskRegistriesView;
517
+ /**
518
+ * 进度上报(可选):执行中主动上报进度,记入 `TaskJob.progress`(`list()` 可见)
519
+ *
520
+ * 进程内直写记录;隔离路径经 postMessage 回传宿主(值必须可结构化克隆,
521
+ * 不可克隆按执行错误处理)。仅 running 状态生效,终态后调用被忽略。
522
+ */
523
+ progress?: (value: unknown) => void;
491
524
  }
492
525
  /**
493
526
  * 任务模块形态(task.ts 编译产物中与执行相关的导出)
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { F as FaapiContext, a as FaapiMiddleware, I as InjectorMap, R as RouteManifest, W as WsRouteManifest, C as CorsOptions, H as HelmetOptions, L as LoggerOptions } from './routeTypes-q9OXB--o.js';
1
+ import { F as FaapiContext, a as FaapiMiddleware, I as InjectorMap, R as RouteManifest, W as WsRouteManifest, C as CorsOptions, H as HelmetOptions, L as LoggerOptions } from './routeTypes-CsL7xtqu.js';
2
2
  import { Server } from 'node:http';
3
3
  import { WebSocket } from 'ws';
4
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faapi/faapi",
3
- "version": "6.5.0",
3
+ "version": "6.7.0",
4
4
  "description": "函数即接口 - Function as API",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",