@@ -2,6 +2,7 @@ import { Command } from 'commander';
22import { TaskService } from '@core/services/task.service' ;
33import { TaskTemplateService } from '@core/services/task-template.service' ;
44import { closeDb } from '@core/db' ;
5+ import { parseDuration } from '@core/duration' ;
56import type { TaskStatus , ScheduleType } from '@core/db/schema' ;
67
78async function withDb < T > ( fn : ( ) => Promise < T > ) : Promise < T > {
@@ -221,8 +222,8 @@ program
221222 . requiredOption ( '-p, --prompt <prompt>' , '提示词' )
222223 . requiredOption ( '-t, --type <type>' , '调度类型:cron/delayed/recurring' )
223224 . option ( '--cron <expr>' , 'cron 表达式(cron 类型必填)' )
224- . option ( '--interval <ms >' , '间隔毫秒(recurring 类型必填)' )
225- . option ( '--run-at <ms >' , '执行时间戳 ms(delayed 类型必填)' )
225+ . option ( '--delay <duration >' , '延迟时间(delayed 类型必填),如 30s / 5min / 1h / 2d ' )
226+ . option ( '--interval <duration >' , '循环间隔(recurring 类型必填),如 1h / 30min / 5s ' )
226227 . option ( '-m, --model <model>' , '模型' )
227228 . option ( '-c, --category <category>' , '分类' , 'general' )
228229 . option ( '-i, --importance <number>' , '重要程度 1-5' , '3' )
@@ -231,6 +232,25 @@ program
231232 . option ( '--max-retries <number>' , '最大重试次数' , '3' )
232233 . option ( '--retry-backoff <ms>' , '退避基础间隔 ms' , '30000' )
233234 . action ( async ( options ) => withDb ( async ( ) => {
235+ let intervalMs : number | null = null ;
236+ let runAt : number | null = null ;
237+
238+ if ( options . interval ) {
239+ intervalMs = parseDuration ( options . interval ) ;
240+ if ( intervalMs === null ) {
241+ console . error ( JSON . stringify ( { error : `Invalid interval: "${ options . interval } ". Use 30s / 5min / 1h / 2d` } ) ) ;
242+ process . exit ( 1 ) ;
243+ }
244+ }
245+ if ( options . delay ) {
246+ const delayMs = parseDuration ( options . delay ) ;
247+ if ( delayMs === null ) {
248+ console . error ( JSON . stringify ( { error : `Invalid delay: "${ options . delay } ". Use 30s / 5min / 1h / 2d` } ) ) ;
249+ process . exit ( 1 ) ;
250+ }
251+ runAt = Date . now ( ) + delayMs ;
252+ }
253+
234254 const tmpl = await TaskTemplateService . create ( {
235255 name : options . name ,
236256 agent : options . agent ,
@@ -241,8 +261,8 @@ program
241261 urgency : parseInt ( options . urgency ) ,
242262 scheduleType : options . type as ScheduleType ,
243263 cronExpr : options . cron ,
244- intervalMs : options . interval ? parseInt ( options . interval ) : null ,
245- runAt : options . runAt ? parseInt ( options . runAt ) : null ,
264+ intervalMs,
265+ runAt,
246266 maxInstances : parseInt ( options . maxInstances ) ,
247267 maxRetries : parseInt ( options . maxRetries ) ,
248268 retryBackoffMs : parseInt ( options . retryBackoff ) ,
0 commit comments