|
6 | 6 | - PHP activities called from Python workflows |
7 | 7 | - Avro payload round-trip across runtimes |
8 | 8 | """ |
| 9 | + |
9 | 10 | from __future__ import annotations |
10 | 11 |
|
11 | | -from durable_workflow import activity, workflow |
| 12 | +from durable_workflow import activity, serializer, workflow |
| 13 | + |
| 14 | +PHP_HISTORY_EVENT_EXPECTED_KEYS = { |
| 15 | + "WorkflowStarted": [ |
| 16 | + "workflow_class", |
| 17 | + "workflow_type", |
| 18 | + "workflow_instance_id", |
| 19 | + "workflow_run_id", |
| 20 | + "workflow_command_id", |
| 21 | + "business_key", |
| 22 | + "visibility_labels", |
| 23 | + "memo", |
| 24 | + "search_attributes", |
| 25 | + "execution_timeout_seconds", |
| 26 | + "run_timeout_seconds", |
| 27 | + "execution_deadline_at", |
| 28 | + "run_deadline_at", |
| 29 | + "workflow_definition_fingerprint", |
| 30 | + "declared_queries", |
| 31 | + "declared_query_contracts", |
| 32 | + "declared_signals", |
| 33 | + "declared_signal_contracts", |
| 34 | + "declared_updates", |
| 35 | + "declared_update_contracts", |
| 36 | + "declared_entry_method", |
| 37 | + "declared_entry_mode", |
| 38 | + "declared_entry_declaring_class", |
| 39 | + ], |
| 40 | + "ActivityCompleted": [ |
| 41 | + "activity_execution_id", |
| 42 | + "activity_attempt_id", |
| 43 | + "activity_class", |
| 44 | + "activity_type", |
| 45 | + "sequence", |
| 46 | + "attempt_number", |
| 47 | + "result", |
| 48 | + "payload_codec", |
| 49 | + "activity", |
| 50 | + "parallel_group_path", |
| 51 | + ], |
| 52 | + "TimerFired": [ |
| 53 | + "timer_id", |
| 54 | + "sequence", |
| 55 | + "delay_seconds", |
| 56 | + "fired_at", |
| 57 | + "timer_kind", |
| 58 | + "condition_wait_id", |
| 59 | + "condition_key", |
| 60 | + "condition_definition_fingerprint", |
| 61 | + "signal_wait_id", |
| 62 | + "signal_name", |
| 63 | + ], |
| 64 | + "SignalReceived": [ |
| 65 | + "workflow_command_id", |
| 66 | + "signal_id", |
| 67 | + "workflow_instance_id", |
| 68 | + "workflow_run_id", |
| 69 | + "signal_name", |
| 70 | + "signal_wait_id", |
| 71 | + "arguments", |
| 72 | + "payload_codec", |
| 73 | + ], |
| 74 | + "UpdateApplied": [ |
| 75 | + "workflow_command_id", |
| 76 | + "update_id", |
| 77 | + "workflow_instance_id", |
| 78 | + "workflow_run_id", |
| 79 | + "update_name", |
| 80 | + "arguments", |
| 81 | + "sequence", |
| 82 | + "payload_codec", |
| 83 | + ], |
| 84 | + "ConditionWaitOpened": [ |
| 85 | + "condition_wait_id", |
| 86 | + "condition_key", |
| 87 | + "condition_definition_fingerprint", |
| 88 | + "sequence", |
| 89 | + "timeout_seconds", |
| 90 | + ], |
| 91 | + "ConditionWaitSatisfied": [ |
| 92 | + "condition_wait_id", |
| 93 | + ], |
| 94 | + "SideEffectRecorded": [ |
| 95 | + "sequence", |
| 96 | + "result", |
| 97 | + "payload_codec", |
| 98 | + ], |
| 99 | + "VersionMarkerRecorded": [ |
| 100 | + "sequence", |
| 101 | + "change_id", |
| 102 | + "version", |
| 103 | + "min_supported", |
| 104 | + "max_supported", |
| 105 | + ], |
| 106 | + "ChildWorkflowScheduled": [ |
| 107 | + "sequence", |
| 108 | + "workflow_link_id", |
| 109 | + "child_call_id", |
| 110 | + "child_workflow_instance_id", |
| 111 | + "child_workflow_run_id", |
| 112 | + "child_workflow_class", |
| 113 | + "child_workflow_type", |
| 114 | + "parent_close_policy", |
| 115 | + "retry_policy", |
| 116 | + "timeout_policy", |
| 117 | + ], |
| 118 | + "ChildRunCompleted": [ |
| 119 | + "sequence", |
| 120 | + "workflow_link_id", |
| 121 | + "child_call_id", |
| 122 | + "child_workflow_instance_id", |
| 123 | + "child_workflow_run_id", |
| 124 | + "child_workflow_class", |
| 125 | + "child_workflow_type", |
| 126 | + "child_run_number", |
| 127 | + "child_status", |
| 128 | + "closed_reason", |
| 129 | + "closed_at", |
| 130 | + "output", |
| 131 | + "parallel_group_path", |
| 132 | + "result", |
| 133 | + "payload_codec", |
| 134 | + ], |
| 135 | + "SearchAttributesUpserted": [ |
| 136 | + "sequence", |
| 137 | + "attributes", |
| 138 | + ], |
| 139 | +} |
| 140 | + |
| 141 | +PHP_HISTORY_EVENT_FIXTURES = [ |
| 142 | + { |
| 143 | + "event_type": "WorkflowStarted", |
| 144 | + "payload": { |
| 145 | + "workflow_class": "Tests\\Fixtures\\V2\\PolyglotWorkflow", |
| 146 | + "workflow_type": "tests.polyglot.history-contract", |
| 147 | + "workflow_instance_id": "wf-polyglot-1", |
| 148 | + "workflow_run_id": "run-polyglot-1", |
| 149 | + "workflow_command_id": "cmd-start-1", |
| 150 | + "business_key": "order-1001", |
| 151 | + "visibility_labels": {"tenant": "acme"}, |
| 152 | + "memo": {"source": "php"}, |
| 153 | + "search_attributes": {"CustomerId": "customer-1"}, |
| 154 | + "execution_timeout_seconds": 3600, |
| 155 | + "run_timeout_seconds": 600, |
| 156 | + "execution_deadline_at": "2026-04-21T21:00:00Z", |
| 157 | + "run_deadline_at": "2026-04-21T20:50:00Z", |
| 158 | + "workflow_definition_fingerprint": "sha256:workflow-definition", |
| 159 | + "declared_queries": ["status"], |
| 160 | + "declared_query_contracts": {"status": {"returns": "object"}}, |
| 161 | + "declared_signals": ["approve"], |
| 162 | + "declared_signal_contracts": {"approve": {"arguments": ["string"]}}, |
| 163 | + "declared_updates": ["rename"], |
| 164 | + "declared_update_contracts": {"rename": {"arguments": ["string"]}}, |
| 165 | + "declared_entry_method": "run", |
| 166 | + "declared_entry_mode": "generator", |
| 167 | + "declared_entry_declaring_class": "Tests\\Fixtures\\V2\\PolyglotWorkflow", |
| 168 | + }, |
| 169 | + }, |
| 170 | + { |
| 171 | + "event_type": "ActivityCompleted", |
| 172 | + "payload": { |
| 173 | + "activity_execution_id": "act-exec-1", |
| 174 | + "activity_attempt_id": "act-attempt-1", |
| 175 | + "activity_class": "Tests\\Fixtures\\V2\\PolyglotActivity", |
| 176 | + "activity_type": "tests.polyglot.activity", |
| 177 | + "sequence": 1, |
| 178 | + "attempt_number": 1, |
| 179 | + "result": serializer.encode({"activity": "ok"}, codec="json"), |
| 180 | + "payload_codec": "json", |
| 181 | + "activity": "tests.polyglot.activity", |
| 182 | + "parallel_group_path": "0", |
| 183 | + }, |
| 184 | + }, |
| 185 | + { |
| 186 | + "event_type": "TimerFired", |
| 187 | + "payload": { |
| 188 | + "timer_id": "timer-1", |
| 189 | + "sequence": 2, |
| 190 | + "delay_seconds": 5, |
| 191 | + "fired_at": "2026-04-21T20:45:00Z", |
| 192 | + "timer_kind": "sleep", |
| 193 | + "condition_wait_id": None, |
| 194 | + "condition_key": None, |
| 195 | + "condition_definition_fingerprint": None, |
| 196 | + "signal_wait_id": None, |
| 197 | + "signal_name": None, |
| 198 | + }, |
| 199 | + }, |
| 200 | + { |
| 201 | + "event_type": "SignalReceived", |
| 202 | + "payload": { |
| 203 | + "workflow_command_id": "cmd-signal-1", |
| 204 | + "signal_id": "sig-1", |
| 205 | + "workflow_instance_id": "wf-polyglot-1", |
| 206 | + "workflow_run_id": "run-polyglot-1", |
| 207 | + "signal_name": "approve", |
| 208 | + "signal_wait_id": "signal-wait-1", |
| 209 | + "arguments": serializer.encode(["alice"], codec="json"), |
| 210 | + "payload_codec": "json", |
| 211 | + }, |
| 212 | + }, |
| 213 | + { |
| 214 | + "event_type": "UpdateApplied", |
| 215 | + "payload": { |
| 216 | + "workflow_command_id": "cmd-update-1", |
| 217 | + "update_id": "upd-1", |
| 218 | + "workflow_instance_id": "wf-polyglot-1", |
| 219 | + "workflow_run_id": "run-polyglot-1", |
| 220 | + "update_name": "rename", |
| 221 | + "arguments": serializer.encode(["new-name"], codec="json"), |
| 222 | + "sequence": 3, |
| 223 | + "payload_codec": "json", |
| 224 | + }, |
| 225 | + }, |
| 226 | + { |
| 227 | + "event_type": "ConditionWaitOpened", |
| 228 | + "payload": { |
| 229 | + "condition_wait_id": "wait-1", |
| 230 | + "condition_key": "approval", |
| 231 | + "condition_definition_fingerprint": None, |
| 232 | + "sequence": 4, |
| 233 | + "timeout_seconds": 30, |
| 234 | + }, |
| 235 | + }, |
| 236 | + { |
| 237 | + "event_type": "ConditionWaitSatisfied", |
| 238 | + "payload": { |
| 239 | + "condition_wait_id": "wait-1", |
| 240 | + }, |
| 241 | + }, |
| 242 | + { |
| 243 | + "event_type": "SideEffectRecorded", |
| 244 | + "payload": { |
| 245 | + "sequence": 5, |
| 246 | + "result": serializer.encode({"side_effect": "stable"}, codec="json"), |
| 247 | + "payload_codec": "json", |
| 248 | + }, |
| 249 | + }, |
| 250 | + { |
| 251 | + "event_type": "ChildWorkflowScheduled", |
| 252 | + "payload": { |
| 253 | + "sequence": 7, |
| 254 | + "workflow_link_id": "link-1", |
| 255 | + "child_call_id": "child-call-1", |
| 256 | + "child_workflow_instance_id": "child-wf-1", |
| 257 | + "child_workflow_run_id": "child-run-1", |
| 258 | + "child_workflow_class": "Tests\\Fixtures\\V2\\ChildWorkflow", |
| 259 | + "child_workflow_type": "tests.polyglot.child", |
| 260 | + "parent_close_policy": "terminate", |
| 261 | + "retry_policy": {"max_attempts": 3, "backoff_seconds": [1, 2]}, |
| 262 | + "timeout_policy": {"execution_timeout_seconds": 120}, |
| 263 | + }, |
| 264 | + }, |
| 265 | + { |
| 266 | + "event_type": "ChildRunCompleted", |
| 267 | + "payload": { |
| 268 | + "sequence": 8, |
| 269 | + "workflow_link_id": "link-1", |
| 270 | + "child_call_id": "child-call-1", |
| 271 | + "child_workflow_instance_id": "child-wf-1", |
| 272 | + "child_workflow_run_id": "child-run-1", |
| 273 | + "child_workflow_class": "Tests\\Fixtures\\V2\\ChildWorkflow", |
| 274 | + "child_workflow_type": "tests.polyglot.child", |
| 275 | + "child_run_number": 1, |
| 276 | + "child_status": "completed", |
| 277 | + "closed_reason": "completed", |
| 278 | + "closed_at": "2026-04-21T20:46:00Z", |
| 279 | + "output": serializer.encode({"child": "ok"}, codec="json"), |
| 280 | + "parallel_group_path": None, |
| 281 | + "result": serializer.encode({"child": "ok"}, codec="json"), |
| 282 | + "payload_codec": "json", |
| 283 | + }, |
| 284 | + }, |
| 285 | + { |
| 286 | + "event_type": "SearchAttributesUpserted", |
| 287 | + "payload": { |
| 288 | + "sequence": 9, |
| 289 | + "attributes": {"status": "done"}, |
| 290 | + }, |
| 291 | + }, |
| 292 | +] |
12 | 293 |
|
13 | 294 | PHP_VERSION_MARKER_RECORDED_EVENT = { |
14 | 295 | "event_type": "VersionMarkerRecorded", |
|
0 commit comments