diff --git a/plugin/task_manager/cluster_comparison/orm.go b/plugin/task_manager/cluster_comparison/orm.go index 5682a61d..51d92911 100644 --- a/plugin/task_manager/cluster_comparison/orm.go +++ b/plugin/task_manager/cluster_comparison/orm.go @@ -56,7 +56,10 @@ func CreateTask(config *migration_model.ClusterComparisonTaskConfig, creator *rb return nil, fmt.Errorf("repeat invalid: %v", err) } - err = orm.Create(nil, t) + ctx := &orm.Context{ + Refresh: "wait_for", + } + err = orm.Create(ctx, t) if err != nil { return nil, err } diff --git a/plugin/task_manager/cluster_migration/orm.go b/plugin/task_manager/cluster_migration/orm.go index ca929772..4dbde582 100644 --- a/plugin/task_manager/cluster_migration/orm.go +++ b/plugin/task_manager/cluster_migration/orm.go @@ -56,7 +56,10 @@ func CreateTask(config *migration_model.ClusterMigrationTaskConfig, creator *rba return nil, fmt.Errorf("repeat invalid: %v", err) } - err = orm.Create(nil, t) + ctx := &orm.Context{ + Refresh: "wait_for", + } + err = orm.Create(ctx, t) if err != nil { return nil, err } diff --git a/plugin/task_manager/common_api.go b/plugin/task_manager/common_api.go index a5444044..3f43a3a8 100644 --- a/plugin/task_manager/common_api.go +++ b/plugin/task_manager/common_api.go @@ -206,7 +206,10 @@ func (h *APIHandler) startTask(w http.ResponseWriter, req *http.Request, ps http } } - err = orm.Update(nil, &obj) + ctx := &orm.Context{ + Refresh: "wait_for", + } + err = orm.Update(ctx, &obj) if err != nil { log.Error(err) h.WriteError(w, err.Error(), http.StatusInternalServerError) @@ -264,12 +267,19 @@ func (h *APIHandler) deleteTask(w http.ResponseWriter, req *http.Request, ps htt h.WriteError(w, fmt.Sprintf("can not delete task [%s] with status [%s]", obj.ID, obj.Status), http.StatusInternalServerError) return } - + ctx := &orm.Context{ + Refresh: "wait_for", + } + err = orm.Delete(ctx, &obj) + if err != nil { + log.Error(err) + h.WriteError(w, err.Error(), http.StatusInternalServerError) + return + } q := util.MapStr{ "query": util.MapStr{ "bool": util.MapStr{ - "minimum_should_match": 1, - "should": []util.MapStr{ + "must": []util.MapStr{ { "term": util.MapStr{ "parent_id": util.MapStr{ @@ -277,22 +287,13 @@ func (h *APIHandler) deleteTask(w http.ResponseWriter, req *http.Request, ps htt }, }, }, - { - "term": util.MapStr{ - "id": util.MapStr{ - "value": id, - }, - }, - }, }, }, }, } err = orm.DeleteBy(&obj, util.MustToJSONBytes(q)) if err != nil { - h.WriteError(w, err.Error(), http.StatusInternalServerError) log.Error(err) - return } h.WriteJSON(w, util.MapStr{ @@ -337,7 +338,10 @@ func (h *APIHandler) resumeTask(w http.ResponseWriter, req *http.Request, ps htt } lastRepeatingChild.Metadata.Labels["repeat_triggered"] = false - err = orm.Update(nil, lastRepeatingChild) + ctx := &orm.Context{ + Refresh: "wait_for", + } + err = orm.Update(ctx, lastRepeatingChild) if err != nil { log.Errorf("failed to update last child, err: %v", err) h.WriteError(w, err.Error(), http.StatusInternalServerError)