[migration] check status before start/stop task

This commit is contained in:
Kassian Sun 2023-04-03 10:04:16 +08:00
parent 7106aaeeda
commit b29dc9ca0f
1 changed files with 10 additions and 0 deletions

View File

@ -227,6 +227,10 @@ func (h *APIHandler) startDataMigration(w http.ResponseWriter, req *http.Request
h.WriteError(w, fmt.Sprintf("task [%s] not found", taskID), http.StatusInternalServerError)
return
}
if obj.Status == task2.StatusComplete {
h.WriteError(w, fmt.Sprintf("task [%s] completed, can't start anymore", taskID), http.StatusInternalServerError)
return
}
obj.Status = task2.StatusReady
err = orm.Update(nil, &obj)
@ -284,6 +288,12 @@ func (h *APIHandler) stopDataMigrationTask(w http.ResponseWriter, req *http.Requ
}, http.StatusNotFound)
return
}
if task2.IsEnded(obj.Status) {
h.WriteJSON(w, util.MapStr{
"success": true,
}, 200)
return
}
//query all pipeline task(scroll/bulk_indexing) and then stop it
err = stopPipelineTasks(id)
if err != nil {