MCPcopy Create free account
hub / github.com/astercloud/aster / Schedule

Method Schedule

pkg/core/scheduler.go:264–280  ·  view source on GitHub ↗

Schedule 使用调度规格创建任务

(spec string, callback TaskCallback)

Source from the content-addressed store, hash-verified

262
263// Schedule 使用调度规格创建任务
264func (s *Scheduler) Schedule(spec string, callback TaskCallback) (string, error) {
265 // 解析规格
266 // 支持格式:
267 // - "step:N" - 每 N 步
268 // - "interval:Ns" - 每 N 秒
269 // - "interval:Nm" - 每 N 分钟
270 // - "cron:* * * * *" - Cron 表达式 (TODO)
271
272 // 简化实现:仅支持 interval
273 var duration time.Duration
274 _, err := fmt.Sscanf(spec, "interval:%s", &duration)
275 if err != nil {
276 return "", fmt.Errorf("invalid schedule spec: %s", spec)
277 }
278
279 return s.EveryInterval(duration, callback)
280}
281
282// Cancel 取消任务
283func (s *Scheduler) Cancel(taskID string) error {

Callers

nothing calls this directly

Calls 1

EveryIntervalMethod · 0.95

Tested by

no test coverage detected