Support dynamic (catch-all) workflows#774
Draft
datashaman wants to merge 1 commit into
Draft
Conversation
Add `#[WorkflowMethod(dynamic: true)]` to declare a dynamic (catch-all) workflow — invoked when the worker receives a workflow whose type name is not statically registered. WorkflowReader flags the prototype; StartWorkflow falls back to the dynamic prototype when no named workflow matches; and the GetWorkerInfo handshake advertises `dynamic` so the RoadRunner temporal plugin can register a Go dynamic-workflow proxy for it. As in the other SDKs (Go panics, Python raises), at most one dynamic workflow may be registered per worker — WorkflowCollection enforces this. Enables Dynamic Workflow support in the PHP SDK (PHP and TypeScript are the only SDKs without it). End-to-end dispatch also requires temporalio/roadrunner-temporal#784 (register the dynamic proxy) and temporalio/sdk-go#2449 (execute a factory-registered dynamic workflow).
6041218 to
17b1122
Compare
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.
What
Adds Dynamic (catch-all) Workflow support — a workflow invoked when the worker receives a type name that is not statically registered. PHP and TypeScript are the only SDKs without it (Go/Java/Python/.NET/Ruby all have it).
#[WorkflowMethod(dynamic: true)]— declares the dynamic workflow. The handler reads the real type viaWorkflow::getInfo()and receives the raw args.WorkflowPrototype::isDynamic()— set byWorkflowReaderfrom the attribute.StartWorkflow— whenworkflows->find($type)misses, falls back to the registered dynamic prototype (mirrors Python'sself._workflows.get(type, self._dynamic_workflow)).GetWorkerInfo— advertisesdynamicper workflow, so the RoadRunner temporal plugin can register a Go dynamic-workflow proxy (Support dynamic (catch-all) workflows roadrunner-temporal#784).WorkflowCollection— enforces at most one dynamic workflow per worker (Go panics, Python raisesTypeError; here aLogicException), since a second catch-all would make dispatch ambiguous.Why
Enables applications that author workflows at runtime (e.g. UI-driven pipeline/automation builders) to give each workflow its own type name — real identity in the Web UI — while one PHP handler interprets it, with no codegen or per-workflow deploy.
Dependencies
End-to-end dispatch needs the rest of the chain:
RegisterDynamicWorkflowwhen thisdynamicfield is set, and needs the go-sdk bump.This PR (the PHP declaration + dispatch) is self-contained and unit-tested independently of those.
Testing
tests/Unit/Declarationcoverage, run against both the attribute and annotation readers:testDynamicWorkflow—#[WorkflowMethod(dynamic: true)]setsisDynamic().testMultipleDynamicWorkflowsAreRejected— a second dynamic workflow on a worker throws.composer run test:unit, 692 tests).composer run cs:diffclean.composer run psalmreports no new issues in the changed files.rr(roadrunner-temporal#784 + go-sdk#2449): starting an unregistered type (pipeline-blog-publish) is caught by the dynamic handler, which reads the real type viaWorkflow::getInfo()and completes.Backwards compatibility
Additive.
dynamicdefaults tofalse, so existing workflows and workers behave exactly as before.