From b29dc9ca0fb39a4f542df3e8962e40af6b735e4f Mon Sep 17 00:00:00 2001 From: Kassian Sun Date: Mon, 3 Apr 2023 10:04:16 +0800 Subject: [PATCH] [migration] check status before start/stop task --- plugin/migration/api.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin/migration/api.go b/plugin/migration/api.go index 9e19c942..cbb1dbe9 100644 --- a/plugin/migration/api.go +++ b/plugin/migration/api.go @@ -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 {