Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(garbage): subtasks are kept until the parent task is in a final state #366

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion engine/collector_garbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"time"

"github.com/loopfz/gadgeto/zesty"

"github.com/ovh/utask"
"github.com/ovh/utask/db/pgjuju"
"github.com/ovh/utask/models/task"
"github.com/ovh/utask/pkg/constants"
"github.com/ovh/utask/pkg/now"
)

Expand Down Expand Up @@ -85,17 +87,25 @@ func GarbageCollector(ctx context.Context, completedTaskExpiration string) error
}

// cascade delete task comments and task resolution
// Subtasks are kept until the parent task is in a final state.
func deleteOldTasks(dbp zesty.DBProvider, perishedThreshold time.Duration) error {
sqlStmt := `DELETE FROM "task"
WHERE "task".state IN ($1,$2,$3)
AND "task".last_activity < $4`
AND "task".last_activity < $4
AND (NOT "task".tags ? $5 OR EXISTS (
SELECT 1 FROM "task" AS parentTask
WHERE parentTask.public_id = ("task".tags->>$5)::uuid
AND parentTask.state IN ($1,$2,$3)
)
)`

if _, err := dbp.DB().Exec(sqlStmt,
// final task states, cannot run anymore
task.StateDone,
task.StateCancelled,
task.StateWontfix,
now.Get().Add(-perishedThreshold),
constants.SubtaskTagParentTaskID,
); err != nil {
return pgjuju.Interpret(err)
}
Expand Down