参照 dict/typecreate.ts:14-66 boilerplate, 给写操作命令补齐三重提醒三重修复: L1 (--verbose/--json stdout 三模式): setupOutputFilter from _output_filter.ts L2 (silent/assertive/suggest 三级 fix): runCommandAutoFix + fetchExistingLists from _auto_fix.ts L3 (CommandLog 落盘, 失败也落): printCommandEnd from _output_filter.ts 修改文件: - print/create.ts (先于dfeb935自动 commit) - org/create.ts - msg/noticecreate.ts (MSERR114) - msg/templatecreate.ts (MSERR114 + 端点修复注释保留) - schedule/create.ts (SYS131 时间关系) - schedule/trigger.ts (W11-D4 手动触发, 仅 L1+L3) - app/login.ts (Phase E base_system 检测 + app 不存在回滚命令) - app/context.ts (新会话第一步入口, L3 落 dbLinkId/forms/menus 数量) 未触及 (留待后续 batch): - app/create.ts: 5-step 复杂创建 (system→DB→DataSource→授权→重登), 5 处 process.exit(1) 需重构为 throw + 集中 try/catch, 超出本轮估算 - app/clear.ts: 30KB destructive 操作, 三层接入风险 > 收益, 需先 --dry-run 保护再接入 - 已知 baseline pre-existing bugs: org/create 的 405 后端路由 fallback 问题, msg/notice 的 GET fallback 405 — 与本 commit 无关 L1 验证: npx tsc --noEmit 0 新错误 (7 文件相关 error 为空) L2/L3 e2e 抽样: - msg templateCreate S-X1/S-X2+L3 跑通 (e2e id=849237951593317317 已清理) - print create S-X1+S-X2+L3 跑通 (前置 commitdfeb935) - app context --json 单行 JSON + L3 落盘跑通
75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
/**
|
|
* commands/schedule/trigger.ts — 手动触发定时任务 (v2.1+ 三层接入)
|
|
*
|
|
* API: POST /api/scheduletask/white/trigger
|
|
*
|
|
* v2.1+ (2026-07-21) 三层接入:
|
|
* L1: --verbose / --json (trigger result 仅 stdout, 无 id 生成, 不走 runCommandAutoFix 但走 stdout 三模式)
|
|
* L3: 触发结果落 CommandLog, 失败也落 (W11-D4 手动触发验证的可见性)
|
|
*/
|
|
import { Command } from 'commander'
|
|
import { JnpfClient } from '../../core/client.ts'
|
|
import { installHelpHook } from '../../core/help.ts'
|
|
import { log } from '../../core/log.ts'
|
|
import { setupOutputFilter, printCommandEnd } from '../_output_filter.ts' // v2.1+ (2026-07-21): stdout 三模式 + CommandLog 落盘
|
|
|
|
interface TriggerOpts {
|
|
id: string
|
|
verbose?: boolean
|
|
json?: boolean
|
|
}
|
|
|
|
export function buildScheduleTriggerCommand(): Command {
|
|
const cmd = new Command('trigger')
|
|
.description('手动触发定时任务 (白名单, 不等 cron)')
|
|
.requiredOption('--id <id>', '定时任务 id')
|
|
.option('--verbose', '完整输出 (含 step machine、API 调用等过程日志)', false)
|
|
.option('--json', '原始 JSON 输出', false)
|
|
.action(async (opts: TriggerOpts) => {
|
|
// v2.1+ L1: stdout 三模式
|
|
setupOutputFilter(opts)
|
|
const c = await JnpfClient.fromToken()
|
|
const startTime = Date.now()
|
|
const r = await c.postJson('/scheduletask/white/trigger', { id: opts.id })
|
|
if (r.code !== 200) {
|
|
log.error(`schedule trigger 失败: ${r.msg}`)
|
|
// v2.1+ L3: 失败落 CommandLog
|
|
printCommandEnd({
|
|
command: 'schedule trigger',
|
|
appCode: c.appCode,
|
|
result: 'failure',
|
|
summary: { id: opts.id },
|
|
error: r.msg || `code=${r.code}`,
|
|
duration_ms: Date.now() - startTime,
|
|
verbose: opts.verbose,
|
|
json: opts.json,
|
|
})
|
|
process.exit(1)
|
|
}
|
|
log.ok(`✓ 定时任务 id=${opts.id} 已触发`)
|
|
// v2.1+ L3: 成功落 CommandLog
|
|
printCommandEnd({
|
|
command: 'schedule trigger',
|
|
appCode: c.appCode,
|
|
summary: { id: opts.id },
|
|
duration_ms: Date.now() - startTime,
|
|
verbose: opts.verbose,
|
|
json: opts.json,
|
|
})
|
|
})
|
|
installHelpHook(cmd, {
|
|
purpose: '手动触发定时任务 (不等 cron, 立即跑)',
|
|
required: { '--id': '定时任务 id' },
|
|
example: 'dacli schedule trigger --id=1234567890',
|
|
source: {
|
|
web: 'web/apps/jnpf-web-apps-main/src/views/teamwork/schedule/Form.vue',
|
|
api: 'POST /api/scheduletask/white/trigger',
|
|
ref: 'doc/v0.8-endpoints.md §2.5',
|
|
},
|
|
notes: [
|
|
'**W11-D4**: 验证定时任务真触发走此命令 + schedule log 拉日志',
|
|
],
|
|
})
|
|
return cmd
|
|
}
|