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

Function demonstrateIntervalTrigger

examples/scheduler/main.go:68–90  ·  view source on GitHub ↗

示例 2: 时间间隔触发

()

Source from the content-addressed store, hash-verified

66
67// 示例 2: 时间间隔触发
68func demonstrateIntervalTrigger() {
69 fmt.Println("--- 示例 2: 时间间隔触发 ---")
70
71 scheduler := core.NewScheduler(nil)
72 defer scheduler.Shutdown()
73
74 // 每 500ms 执行一次
75 taskID, err := scheduler.EveryInterval(500*time.Millisecond, func(ctx context.Context) error {
76 fmt.Printf("✓ 定时任务触发: %s\n", time.Now().Format("15:04:05.000"))
77 return nil
78 })
79
80 if err != nil {
81 log.Fatalf("创建定时任务失败: %v", err)
82 }
83
84 fmt.Printf("定时任务已创建: %s\n", taskID)
85 fmt.Println("运行 2 秒...")
86
87 // 运行 2 秒
88 time.Sleep(2 * time.Second)
89 fmt.Println()
90}
91
92// 示例 3: 步骤监听器
93func demonstrateStepListeners() {

Callers 1

mainFunction · 0.85

Calls 4

ShutdownMethod · 0.95
EveryIntervalMethod · 0.95
NewSchedulerFunction · 0.92
PrintfMethod · 0.80

Tested by

no test coverage detected