Skip to content

Periodic workflows#41

Draft
daviddavis wants to merge 1 commit into
pulp:mainfrom
daviddavis:periodic-workflows
Draft

Periodic workflows#41
daviddavis wants to merge 1 commit into
pulp:mainfrom
daviddavis:periodic-workflows

Conversation

@daviddavis

Copy link
Copy Markdown
Collaborator

Added support for periodic workflows. A Workflow can now be given a dispatch_interval, in which case it re-runs on that recurring schedule instead of running just once at start_time.

fixes #20

Assisted-by: GitHub Copilot (Claude Opus 4.8)

📜 Checklist

  • Commits are cleanly separated with meaningful messages (simple features and bug fixes should be squashed to one commit)
  • A changelog entry or entries has been added for any significant changes
  • Follows the Pulp policy on AI Usage
  • (For new features) - User documentation and test coverage has been added

See: Pull Request Walkthrough

@daviddavis
daviddavis force-pushed the periodic-workflows branch from c4e7164 to 88ef818 Compare July 17, 2026 12:51
Added support for periodic workflows. A `Workflow` can now be given a
`dispatch_interval`, in which case it re-runs on that recurring schedule
instead of running just once at `start_time`.

fixes pulp#20

Assisted-by: GitHub Copilot (Claude Opus 4.8)
@daviddavis
daviddavis force-pushed the periodic-workflows branch from 88ef818 to 142fe8b Compare July 17, 2026 13:16
@daviddavis
daviddavis marked this pull request as ready for review July 17, 2026 13:28
Copilot AI review requested due to automatic review settings July 17, 2026 13:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces periodic workflow execution by splitting workflow definition/schedule (Workflow) from workflow execution state (WorkflowRun), allowing a workflow to create recurring runs when dispatch_interval is set.

Changes:

  • Added WorkflowRun model + API endpoint and moved execution state (state, timestamps, error, current_task, task_group) from Workflow onto WorkflowRun.
  • Implemented periodic scheduling via dispatch_interval by scheduling start_workflow_run, which creates a run and dispatches execution.
  • Updated cancellation semantics (stop workflow vs cancel run) and adjusted callback execution/environment to be run-aware; expanded unit + functional coverage.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
pulp_workflow/app/models.py Introduces WorkflowRun and moves execution-state semantics off Workflow.
pulp_workflow/app/serializers.py Adds dispatch_interval to workflows and introduces WorkflowRunSerializer; schedules start_workflow_run.
pulp_workflow/app/tasks.py Adds start_workflow_run; updates execution/callback dispatch to be run-based.
pulp_workflow/app/viewsets.py Adds WorkflowRunViewSet; changes workflow PATCH to “stop schedule + cancel in-flight runs”.
pulp_workflow/app/signals.py Updates TaskGroup cancel propagation to operate on WorkflowRun.
pulp_workflow/app/migrations/0005_workflowrun.py Schema + data migration to add runs, remove old workflow execution fields, and rewrite schedules.
pulp_workflow/pytest_plugin.py Updates fixtures/helpers to monitor runs instead of workflows.
pulp_workflow/tests/unit/test_viewsets.py Adds unit coverage for run permissions/access policy behavior.
pulp_workflow/tests/unit/test_tasks.py Updates unit tests for run-based task execution and start_workflow_run.
pulp_workflow/tests/unit/test_models.py Adjusts callback env tests to use a run wrapper (run state + workflow metadata).
pulp_workflow/tests/functional/api/test_execute_workflow.py Refactors functional assertions to target runs + TaskGroups rather than workflow state.
pulp_workflow/tests/functional/api/test_crud_workflows.py Updates CRUD expectations and stop semantics to be run-based.
pulp_workflow/tests/functional/api/test_workflow_callbacks.py Updates callback functional tests and adds cancellation callback coverage.
pulp_workflow/tests/functional/api/test_periodic_workflow.py Adds functional coverage for periodic run creation and non-overlap behavior.
docs/design.md Updates design documentation to describe definition vs run split and scheduling/cancel flows.
CHANGES/20.feature Changelog entry for periodic workflows + new WorkflowRun resource.
CHANGES/20.removal Changelog entry for removed fields from Workflow / WorkflowTask.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 158 to +161
workflow = self.get_object()
fired_callbacks = False
# Stop future runs by removing the schedule.
TaskSchedule.objects.filter(name=f"pulp_workflow.workflow:{workflow.pk}").delete()

Comment on lines +32 to +35
for run in runs:
run.state = TASK_STATES.CANCELED
run.finished_at = timezone.now()
run.save(update_fields=["state", "finished_at", "pulp_last_updated"])
Comment thread docs/design.md
Comment on lines +31 to +35
`start_workflow_run` is deliberately tiny: it creates a `WorkflowRun` and its
`TaskGroup`, then dispatches the first `execute_workflow` step and returns.
Because it completes almost immediately, the scheduler's
"don't dispatch while the last task is still running" guard does not serialize
runs — overlapping runs of a periodic workflow are allowed by design.
Comment on lines +106 to +110
Each time a workflow's schedule fires, a ``WorkflowRun`` is created to track that
execution's state independently of the workflow definition and of any other run.
This lets a periodic workflow keep a full history of its runs, and lets concurrent
(overlapping) runs of the same workflow coexist.

Comment on lines +9 to +12
# Move per-execution state onto WorkflowRun and repoint each workflow's schedule from
# execute_workflow at start_workflow_run. start_workflow_run reuses the schedule's existing
# workflow_pk kwarg, so rewriting only task_name revives pending ("waiting") schedules.
# Prior run history (completed/failed/in-flight) is dropped and not back-filled as WorkflowRun rows.
@daviddavis
daviddavis marked this pull request as draft July 17, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow users to schedule workflows to run periodically (e.g. every day)

2 participants