[cherry-pick] fix: clean the redis if the execution is not found (#18519)

fix: clean the redis if the execution is not found

Delete the execution outdated status key in the redis when the execution
is not found.

Fixes: #18511

Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
Chlins Zhang 2023-04-13 10:55:26 +08:00 committed by GitHub
parent 9ea2d3cbd9
commit 47f70cba86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -476,6 +476,14 @@ func scanAndRefreshOutdateStatus(ctx context.Context) {
statusChanged, currentStatus, err := ExecDAO.RefreshStatus(ctx, execID)
if err != nil {
// no need to refresh and should clean cache if the execution is not found
if errors.IsNotFoundErr(err) {
if err = cache.Default().Delete(ctx, key); err != nil {
log.Errorf("failed to delete the key %s in cache, error: %v", key, err)
}
succeed++
continue
}
log.Errorf("failed to refresh the status of execution %d, error: %v", execID, err)
failed++
continue

View File

@ -139,7 +139,7 @@ func (sm *sweepManager) ListCandidates(ctx context.Context, vendorType string, r
n = n + 1
}
sql = `SELECT id FROM execution WHERE vendor_type = ? AND vendor_id = ? AND start_time < ? AND status IN (?,?,?)`
sql = `SELECT id FROM execution WHERE vendor_type = ? AND vendor_id = ? AND start_time < ? AND status IN (?,?,?) ORDER BY id`
// default page size is 100000
q2 := &q.Query{PageSize: int64(defaultPageSize)}
for i := n; i >= 1; i-- {