feat(schedule): v0.11e+ wire up _validate.ts + enhanceFromBackend
schedule/create.ts (Phase C1 集成): - import validateScheduleCreate + enhanceFromBackend/formatErrorLine - 加 --startTime/--endTime/--enabledMark 选项 - 跑 step machine (cron 格式校验 + SYS131 时间关系) - catch 后端错时 enhanceFromBackend
This commit is contained in:
1 parent
7e809c56b4
commit
1881bec301
1 file changed
+31
-2
@@ -9,6 +9,8 @@ import { JnpfClient } from '../../core/client.ts'
|
||||
import { installAiHelpHook } from '../../core/help.ts'
|
||||
import { log, printJson } from '../../core/log.ts'
|
||||
import { initWebapi, loadSchedule } from '../../webapi/schedule.ts'
|
||||
import { validateScheduleCreate } from './_validate.ts'
|
||||
import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts'
|
||||
|
||||
interface CreateOpts {
|
||||
fullName: string
|
||||
@@ -16,21 +18,47 @@ interface CreateOpts {
|
||||
executeType: string
|
||||
executeContent: string
|
||||
cron?: string
|
||||
startTime?: string
|
||||
endTime?: string
|
||||
enabledMark?: string
|
||||
json?: boolean
|
||||
}
|
||||
|
||||
export function buildScheduleCreateCommand(): Command {
|
||||
const cmd = new Command('create')
|
||||
.description('新建定时任务 (Quartz cron, v0.11+ webapi)')
|
||||
.description('新建定时任务 (Quartz cron, v0.11+ webapi + v0.11e+ step machine)')
|
||||
.requiredOption('--fullName <name>', '任务名称')
|
||||
.requiredOption('--enCode <code>', '任务编码')
|
||||
.requiredOption('--executeType <t>', '执行类型 (e.g. SQL/JavaScript/...)')
|
||||
.requiredOption('--executeContent <c>', '执行内容 (SQL 脚本/JS 代码)')
|
||||
.option('--cron <expr>', 'cron 表达式 (e.g. "0 0 0 * * ?")')
|
||||
.option('--startTime <iso>', 'v0.11e+ Phase C1: 开始时间 (ISO 格式, SYS131 校验)')
|
||||
.option('--endTime <iso>', 'v0.11e+ Phase C1: 结束时间 (ISO 格式, SYS131 校验)')
|
||||
.option('--enabledMark <m>', 'v0.11e+ Phase C1: 0/1', '1')
|
||||
.option('--json', '原始 JSON 输出', false)
|
||||
.action(async (opts: CreateOpts) => {
|
||||
const c = await JnpfClient.fromToken()
|
||||
await initWebapi(c)
|
||||
|
||||
// v0.11e+ Phase C1: step machine 校验 (cron 格式 + SYS131 时间关系)
|
||||
const validation = validateScheduleCreate({
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
cron: opts.cron,
|
||||
startTime: opts.startTime,
|
||||
endTime: opts.endTime,
|
||||
enabledMark: opts.enabledMark,
|
||||
})
|
||||
if (!validation.ok) {
|
||||
for (const s of validation.steps) {
|
||||
for (const e of s.errors) {
|
||||
log.error(` ${formatErrorLine(e, { step: s.step, stepName: s.stepName })}`)
|
||||
}
|
||||
}
|
||||
process.exit(1)
|
||||
}
|
||||
log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`)
|
||||
|
||||
const body: Record<string, unknown> = {
|
||||
fullName: opts.fullName,
|
||||
enCode: opts.enCode,
|
||||
@@ -43,7 +71,8 @@ export function buildScheduleCreateCommand(): Command {
|
||||
log.info(`loadSchedule.create (enCode=${opts.enCode})`)
|
||||
const r = (await loadSchedule.create(body)) as { id?: string; code?: number; msg?: string; data?: { id?: string } }
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
log.error(`schedule create 失败: ${r.msg}`)
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'schedule', { entity: 'schedule' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
process.exit(1)
|
||||
}
|
||||
const id = r.id || r.data?.id
|
||||
|
||||
Reference in new issue
Block a user