[task_manager] fix auto start
This commit is contained in:
parent
0cb91e7c78
commit
bd69c89780
|
@ -316,6 +316,10 @@ func (h *APIHandler) getMigrationMajorTaskInfo(id string) (taskStats migration_m
|
||||||
indexMigrationTaskIDs = append(indexMigrationTaskIDs, subTask.ID)
|
indexMigrationTaskIDs = append(indexMigrationTaskIDs, subTask.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(indexMigrationTaskIDs) == 0 {
|
||||||
|
return taskStats, indexState, nil
|
||||||
|
}
|
||||||
|
|
||||||
taskQuery = util.MapStr{
|
taskQuery = util.MapStr{
|
||||||
"size": 500,
|
"size": 500,
|
||||||
"query": util.MapStr{
|
"query": util.MapStr{
|
||||||
|
|
|
@ -7,16 +7,27 @@ import (
|
||||||
"infini.sh/framework/core/util"
|
"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 {
|
func UpdateRepeatState(repeat *migration_model.Repeat, labels util.MapStr) error {
|
||||||
if labels == nil {
|
if labels == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
if repeat == nil {
|
||||||
if !isValidRepeat(repeat) {
|
|
||||||
labels["repeat_done"] = true
|
labels["repeat_done"] = true
|
||||||
return nil
|
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 := GetMapIntValue(labels, "run_times")
|
||||||
runTimes += 1
|
runTimes += 1
|
||||||
|
@ -43,7 +54,10 @@ func CopyRepeatState(oldLabels, newLabels util.MapStr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsRepeating(repeat *migration_model.Repeat, labels map[string]interface{}) bool {
|
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
|
return false
|
||||||
}
|
}
|
||||||
if repeat.TotalRun < 1 {
|
if repeat.TotalRun < 1 {
|
||||||
|
@ -63,13 +77,3 @@ func IsRepeating(repeat *migration_model.Repeat, labels map[string]interface{})
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func isValidRepeat(repeat *migration_model.Repeat) bool {
|
|
||||||
if repeat == nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if repeat.Interval < time.Minute {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue