Skip to content

Commit

Permalink
Fixes 4792: template tasks deleted causing invalid status (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
xbhouse authored Oct 9, 2024
1 parent 1153126 commit c2b23d2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/dao/task_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,11 @@ func (t taskInfoDaoImpl) List(
func (t taskInfoDaoImpl) Cleanup(ctx context.Context) error {
// Delete all completed or failed specified tasks that are older than 10 days
// Delete all finished delete tasks that are older 10 days
// Do not delete tasks if they are the last update-template-content task that updated a template
q := "delete from tasks where " +
"(type in (%v) and (status = 'completed' or status = 'failed') and finished_at < (current_date - interval '20' day)) OR" +
"(type in (%v) and status = 'completed' and finished_at < (current_date - interval '10' day))"
"((type in (%v) and (status = 'completed' or status = 'failed') and finished_at < (current_date - interval '20' day)) OR" +
"(type in (%v) and status = 'completed' and finished_at < (current_date - interval '10' day)))" +
"AND NOT EXISTS (SELECT 1 FROM templates WHERE templates.last_update_task_uuid = tasks.id)"
q = fmt.Sprintf(q, stringSliceToQueryList(config.TasksToCleanup), stringSliceToQueryList(config.TasksToCleanupIfCompleted))
result := t.db.WithContext(ctx).Exec(q)
if result.Error != nil {
Expand Down

0 comments on commit c2b23d2

Please sign in to comment.