feat: nightly purge of obsolete workflow_runs #678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
We planed to “delete old test rows” but deleting the parent
workflow_run
instead is simpler:DELETE
onworkflow_run
removes the entiresuite
→case
hierarchy and the matching rows inhelios_deployment
I also added support to have different retention rules for different processing results (PROCESSED, FAILED, NULL).
Description
Config
cleanup.workflow-run
: cron + ordered list of policies.The list is ordered; each run is evaluated by the first policy whose status matches.
Code
WorkflowRunCleanupProps
binds the YAML. Missing age-days → 0 (= “no age filter”).WorkflowRunCleanupTask
runs on a configurable cron, loops over the policies, and callsWorkflowRunRepository.purgeObsoleteRuns()
purgeObsoleteRuns()
is plain SQL:repository + workflow + branch
bucket the query sorts the rows bycreated_at
(newest first) and numbers them 1, 2, 3 … withrow_number()
.≤ keep
is untouchable for that policy. Everything ranked>keep
becomes a candidate for deletion.created_at <= 5
then it will be deleted.Flyway
helios_deployment
andworkflow_run
and recreates it with on delete cascadeBehaviour
With this setup, the cleanup keeps the latest two PROCESSED runs for each (repository, workflow, branch) and deletes any older ones right away. For FAILED and NULL runs, we again keep the latest two, but give older ones a 5-day grace period before deleting them.
Why it's safe to remove old helios_deployment rows
Deployments are tied to
workflow_run
rows (at the first place), and now that we keep the latest two NULL-status (test_process) workflow runs, we’re guaranteed to retain current/in-progress deployment records. These are the only ones needed for UI pages like the deployment history page, which query the deployment table whenever the process is completed. Since we're not deleting everything and we are keeping the latest N records it’s safe to let the database remove olderhelios_deployment
rows when their parent workflow run is deleted.