Skip to content

Commit 978739d

Browse files
committed
refactor: refactor schedule task registration function
- Remove `registerScheduleTasks` function - Add a new implementation of `registerScheduleTasks` function Signed-off-by: Bo-Yi.Wu <[email protected]>
1 parent b815dac commit 978739d

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

services/cron/tasks_actions.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,6 @@ func initActionsTasks() {
2121
registerScheduleTasks()
2222
}
2323

24-
func registerScheduleTasks() {
25-
RegisterTaskFatal("start_schedule_tasks", &BaseConfig{
26-
Enabled: true,
27-
RunAtStart: false,
28-
Schedule: "@every 1m",
29-
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
30-
return actions_service.StartScheduleTasks(ctx)
31-
})
32-
}
33-
3424
func registerStopZombieTasks() {
3525
RegisterTaskFatal("stop_zombie_tasks", &BaseConfig{
3626
Enabled: true,
@@ -60,3 +50,16 @@ func registerCancelAbandonedJobs() {
6050
return actions_service.CancelAbandonedJobs(ctx)
6151
})
6252
}
53+
54+
// registerScheduleTasks registers a scheduled task that runs every minute to start any due schedule tasks.
55+
func registerScheduleTasks() {
56+
// Register the task with a unique name, enabled status, and schedule for every minute.
57+
RegisterTaskFatal("start_schedule_tasks", &BaseConfig{
58+
Enabled: true,
59+
RunAtStart: false,
60+
Schedule: "@every 1m",
61+
}, func(ctx context.Context, _ *user_model.User, cfg Config) error {
62+
// Call the function to start schedule tasks and pass the context.
63+
return actions_service.StartScheduleTasks(ctx)
64+
})
65+
}

0 commit comments

Comments
 (0)