Add a manual purge action for completed Workflows
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1
- Forks
- 3
- Avg merge
- 4d 8h
- Merged PRs (30d)
- 4
Description
Summary
Add a manual API for purging completed Workflow records, mirroring the existing pulpcore POST /pulp/api/v3/tasks/purge/ action.
Motivation
Workflows accumulate the same way tasks do — once completed, the rows stay around for audit/history but eventually become noise. Pulpcore already provides this for tasks via the tasks_purge action; workflows should have the equivalent so operators have a way to keep the workflow table tidy.
Explicitly manual, not automatic: like pulpcore's task purge, the action should only run when an operator (or a scheduled job they configure themselves) invokes it. No background sweeping should be added.
How pulpcore does it (for reference)
POST /pulp/api/v3/tasks/purge/is an@action(detail=False, methods=["post"])onTaskViewSet(pulpcore/app/viewsets/task.py).- The action accepts a
PurgeSerializerbody with two fields (pulpcore/app/serializers/purge.py):finished_before— datetime; defaults to 30 days ago.states— set of allowed final states; defaults to["completed"], restricted toTASK_FINAL_STATES.
- The action dispatches
pulpcore.app.tasks.purge.purgeand returns anOperationPostponedResponse(202). - The purge task is itself a regular pulp task: it filters in chunks of 1000, scopes by current domain and
core.delete_taskpermission, and emitsProgressReports for totals, per-type counts, and errors. - A
tasksentry is registered inINITIAL_GUARDED_SCHEDULES(pulpcore/app/util.py) so a default schedule exists, but the user is in control of whether it actually runs.
Proposed design for pulp_workflow
Add a purge action on WorkflowViewSet:
POST /pulp/api/v3/workflows/purge/(action,detail=False,methods=["post"]).- Request body —
WorkflowPurgeSerializer:finished_before—DateTimeField, defaultnow() - 30d. Only workflows whosefinished_atis strictly less than this are eligible.states—MultipleChoiceFieldover the workflow's terminal states (COMPLETED,FAILED,CANCELED); default["completed"].
- Dispatch a new task
pulp_workflow.app.tasks.purge_workflowsand returnOperationPostponedResponse(202). Do not run synchronously. - Permission model:
- Add a
delete_workflowDjango permission toWorkflow.Meta.permissions(or rely on the defaultdeletepermission once added) and gate the action on it viaDEFAULT_ACCESS_POLICY, mirroring pulpcore's pattern of filtering bydelete_taskinside the purge task. - Scope by current domain (
pulp_domain=get_domain()) when the task was dispatched by a user (i.e. not from a schedule).
- Add a
- Inside
purge_workflows:- Build a queryset of
Workflow.objects.filter(finished_at__lt=finished_before, state__in=states). - Delete in chunks of 1000 to keep memory bounded (same
DELETE_LIMITpattern as pulpcore). - Emit
ProgressReports with codes such aspurge.workflows.total,purge.workflows.key.<model>,purge.workflows.errorfor parity with the task purge.
- Build a queryset of
- Cascade behavior:
WorkflowTask,WorkflowTaskArg, andWorkflowTaskKwargalready cascade offWorkflowviaon_delete=CASCADE, so deleting theWorkflowcleans those up automatically. The associatedTaskGroup(once #3 lands) and the childTaskrows are not owned by the workflow and should be left alone — they are governed bytasks_purge. Document this in the action's help text so users understand they need to run both.
Explicitly out of scope
- No automatic/scheduled purging by default. Do not add a
TaskScheduleentry that runs on its own. Operators who want recurring purges can create their ownTaskSchedulepointing atpulp_workflow.app.tasks.purge_workflows. - No purge of running or waiting workflows. The
statesfield must reject non-terminal states (validate in the serializer the same way pulpcore'sPurgeSerializerrestricts toTASK_FINAL_STATES). - No deletion of the
Taskrows the workflow dispatched. Those are pulpcore's responsibility.
Acceptance criteria
POST /pulp/api/v3/workflows/purge/exists, acceptsfinished_beforeandstates, returns 202 with a task reference.- Dispatched task removes only workflows whose
finished_at < finished_beforeand whosestateis in the (validated terminal)stateslist. - Workflows in non-terminal states are never deleted.
- Cascading delete of
WorkflowTask/WorkflowTaskArg/WorkflowTaskKwargworks. - Default
finished_beforeis "30 days ago" and defaultstatesis["completed"]. - Domain scoping matches pulpcore's task purge (current-domain only when dispatched by a user).
- Permission check prevents users without
delete_workflowfrom purging. - Functional test covers: defaults spare recent workflows; explicit
finished_beforein the future deletes everything terminal; non-terminal workflows are spared regardless.
Related
- pulpcore reference implementation:
pulpcore/app/tasks/purge.py,pulpcore/app/viewsets/task.py,pulpcore/app/serializers/purge.py.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing WorkflowViewSet, WorkflowPurgeSerializer, and the proposed purge_workflows task with pulpcore's task.py, purge.py, and serializers/purge.py reference implementations. Done means the purge endpoint returns 202, validates terminal states and permissions, applies the stated domain and date filters, cascades workflow-owned rows, and has the described functional coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- api, authorization, backend, database, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100