Skip to content

Commit d24901b

Browse files
committed
Support dynamic (catch-all) workflows
Allow a PHP worker to register a dynamic (catch-all) workflow, invoked for any workflow type name that has no statically registered handler. The host already registers a single shared WorkflowDefinitionFactory proxy (wDef) under each declared name; when a workflow is declared dynamic, register that same proxy via worker.RegisterDynamicWorkflow instead (it forwards the real workflow type name to PHP), and skip named registration for it. WorkflowInfo gains a Dynamic field, populated from the "dynamic" key the PHP GetWorkerInfo handshake emits. This enables Dynamic Workflow support in the PHP SDK (PHP and TypeScript are the only SDKs without it). Companion change: temporalio/sdk-php. Depends on temporalio/sdk-go#2449 (issue #2448): RegisterDynamicWorkflow accepts the factory, but go-sdk's dynamic execution path panics on it until that fix ships. A go.temporal.io/sdk bump to the first release containing it is required before dynamic dispatch runs.
1 parent 0818562 commit d24901b

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

aggregatedpool/workers.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ func TemporalWorkers(wDef *Workflow, actDef *Activity, wi []*internal.WorkerInfo
149149
for j := 0; j < len(wi[i].Workflows); j++ {
150150
wf := wi[i].Workflows[j]
151151

152+
// A dynamic workflow is the catch-all: register it via
153+
// RegisterDynamicWorkflow (not by name) so it handles any workflow
154+
// type that has no statically registered handler. The shared proxy
155+
// (wDef) is a WorkflowDefinitionFactory, which RegisterDynamicWorkflow
156+
// accepts; it forwards the real workflow type name to PHP.
157+
if wf.Dynamic {
158+
err := registerWorkflow(func() {
159+
wrk.RegisterDynamicWorkflow(wDef, workflow.DynamicRegisterOptions{})
160+
}, wf.Name, wi[i].TaskQueue)
161+
if err != nil {
162+
return nil, err
163+
}
164+
165+
log.Debug("dynamic workflow registered", zap.String(tq, wi[i].TaskQueue), zap.Any("workflow name", wf.Name))
166+
167+
continue
168+
}
169+
152170
err := registerWorkflow(func() {
153171
wrk.RegisterWorkflowWithOptions(wDef, workflow.RegisterOptions{
154172
Name: wf.Name,

internal/worker_info.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ type WorkflowInfo struct {
3333
Signals []string `json:"signals"`
3434
// VersioningBehavior for the workflow.
3535
VersioningBehavior workflow.VersioningBehavior `json:"versioning_behavior,omitempty"`
36+
// Dynamic marks this as the catch-all workflow, registered via
37+
// RegisterDynamicWorkflow so it handles any otherwise-unregistered type.
38+
Dynamic bool `json:"dynamic,omitempty"`
3639
}
3740

3841
// ActivityInfo describes single worker activity.

0 commit comments

Comments
 (0)