Merge pull request #12668 from chlins/fix/preheat-delete-policy

fix(preheat): check running executions when delete policy
This commit is contained in:
Steven Zou 2020-08-06 16:47:53 +08:00 committed by GitHub
commit 4f90ebce9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,6 +275,27 @@ func (api *preheatAPI) DeletePolicy(ctx context.Context, params operation.Delete
return api.SendError(ctx, err)
}
detectRunningExecutions := func(executions []*task.Execution) error {
for _, exec := range executions {
if exec.Status == job.RunningStatus.String() {
return fmt.Errorf("execution %d under the policy %s is running, stop it and retry", exec.ID, policy.Name)
}
}
return nil
}
executions, err := api.executionCtl.List(ctx, &q.Query{Keywords: map[string]interface{}{
"vendor_type": job.P2PPreheat,
"vendor_id": policy.ID,
}})
if err != nil {
return api.SendError(ctx, err)
}
// Detecting running tasks under the policy
if err = detectRunningExecutions(executions); err != nil {
return api.SendError(ctx, err)
}
err = api.preheatCtl.DeletePolicy(ctx, policy.ID)
if err != nil {
return api.SendError(ctx, err)