[task_manager] fix auto start

This commit is contained in:
Kassian Sun 2023-06-16 08:22:24 +08:00 committed by Gitea
parent 0cb91e7c78
commit bd69c89780
2 changed files with 22 additions and 14 deletions

View File

@ -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{

View File

@ -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
}