fix: update the execution sweep sql to resolve the exec deletion conflict (#20603)

fix: update the execution sweep sql to resolve the exec deleteion conflict

Resolve the execution deleteion conflict when there are tasks still
referenced by the execution, remained execs can wait for next sweep
cycle.

Signed-off-by: chlins <chlins.zhang@gmail.com>
Co-authored-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
Chlins Zhang 2024-06-17 18:29:43 +08:00 committed by GitHub
parent 793dc54aec
commit df4ab856c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -176,7 +176,7 @@ func (sm *sweepManager) Clean(ctx context.Context, execIDs []int64) error {
return errors.Wrap(err, "failed to delete tasks")
}
// delete executions
sql = fmt.Sprintf("DELETE FROM execution WHERE id IN (%s)", orm.ParamPlaceholderForIn(len(params)))
sql = fmt.Sprintf("DELETE FROM execution WHERE id IN (%s) AND id NOT IN (SELECT DISTINCT execution_id FROM task)", orm.ParamPlaceholderForIn(len(params)))
_, err = ormer.Raw(sql, params...).Exec()
if err != nil {
return errors.Wrap(err, "failed to delete executions")