From bd69c8978079dd68b2027a9c0f4bed57e3da95d3 Mon Sep 17 00:00:00 2001 From: Kassian Sun Date: Fri, 16 Jun 2023 08:22:24 +0800 Subject: [PATCH] [task_manager] fix auto start --- plugin/task_manager/migration_api.go | 4 ++++ plugin/task_manager/util/repeat.go | 32 ++++++++++++++++------------ 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/plugin/task_manager/migration_api.go b/plugin/task_manager/migration_api.go index afd28a69..44f7973d 100644 --- a/plugin/task_manager/migration_api.go +++ b/plugin/task_manager/migration_api.go @@ -316,6 +316,10 @@ func (h *APIHandler) getMigrationMajorTaskInfo(id string) (taskStats migration_m indexMigrationTaskIDs = append(indexMigrationTaskIDs, subTask.ID) } + if len(indexMigrationTaskIDs) == 0 { + return taskStats, indexState, nil + } + taskQuery = util.MapStr{ "size": 500, "query": util.MapStr{ diff --git a/plugin/task_manager/util/repeat.go b/plugin/task_manager/util/repeat.go index eafa632d..48f52ac2 100644 --- a/plugin/task_manager/util/repeat.go +++ b/plugin/task_manager/util/repeat.go @@ -7,16 +7,27 @@ import ( "infini.sh/framework/core/util" ) +/* +is_repeat: task will repeat for more than 1 time +run_times: the total number of runs of a repeating task +repeat_done: task has reached the last repeat +next_run_time: the time this task will get picked by scheduler to start +repeat_triggered: the task has been picked by scheduler and started +*/ func UpdateRepeatState(repeat *migration_model.Repeat, labels util.MapStr) error { if labels == nil { return nil } - - if !isValidRepeat(repeat) { + if repeat == nil { labels["repeat_done"] = true return nil } - labels["is_repeat"] = true + + if repeat.Interval >= time.Minute { + labels["is_repeat"] = true + } else { + labels["repeat_done"] = true + } runTimes := GetMapIntValue(labels, "run_times") runTimes += 1 @@ -43,7 +54,10 @@ func CopyRepeatState(oldLabels, newLabels util.MapStr) { } func IsRepeating(repeat *migration_model.Repeat, labels map[string]interface{}) bool { - if !isValidRepeat(repeat) { + if repeat == nil { + return false + } + if repeat.Interval < time.Minute { return false } if repeat.TotalRun < 1 { @@ -63,13 +77,3 @@ func IsRepeating(repeat *migration_model.Repeat, labels map[string]interface{}) } return false } - -func isValidRepeat(repeat *migration_model.Repeat) bool { - if repeat == nil { - return false - } - if repeat.Interval < time.Minute { - return false - } - return true -}