Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
Optimizes empty workflow handling by processing completion callbacks without scheduling an unnecessary no-op task when no delay is specified.
- Adds tests for empty Chain and Group workflows.
- Implements direct callback processing in Workflow.__schedule_noop when no delay is provided.
- Introduces a new _process_completion_callbacks method in the middleware.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| dramatiq_workflow/tests/test_workflow.py | Adds tests ensuring that empty workflows skip broker enqueue and process callbacks correctly. |
| dramatiq_workflow/_middleware.py | Introduces _process_completion_callbacks to process workflow completion callbacks immediately. |
| dramatiq_workflow/_base.py | Updates __schedule_noop to call _process_completion_callbacks when there's no delay, avoiding a no‑op task. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR optimizes the handling of empty
ChainorGroupworkflows. Instead of scheduling a noop task and relying on the middleware to process completion callbacks, this change processes them directly within theWorkflow.runmethod when there is no delay. This avoids an unnecessary round trip to the broker.Why do we even support empty
Chains andGroups?Empty chains and groups are common when created programmatically:
In this example,
work_itemsmight be empty, in which casefinalize_workshould run immediately.