|
98 | 98 | Command, |
99 | 99 | FailWorkflow, |
100 | 100 | LocalActivityExecutionAborted, |
101 | | - NexusServiceCall, |
102 | 101 | PreparedLocalActivityCall, |
103 | 102 | RecordLocalActivity, |
104 | | - RecordSideEffect, |
105 | 103 | ReplayOutcome, |
106 | 104 | ScheduleActivity, |
107 | 105 | StartChildWorkflow, |
|
166 | 164 | } |
167 | 165 | _WORKFLOW_TASK_COMPLETION_MAX_ATTEMPTS = 3 |
168 | 166 | _WORKFLOW_TASK_COMPLETION_RETRY_DELAYS = (0.05, 0.2) |
169 | | -_WORKFLOW_TASK_NEXUS_RESOLUTION_LIMIT = 100 |
170 | 167 | _LOCAL_ACTIVITY_REPORT_LIMIT = 1000 |
171 | 168 | _WORKER_WORKFLOW_FINGERPRINTS: dict[tuple[str, str], str] = {} |
172 | 169 | _P = ParamSpec("_P") |
@@ -1428,86 +1425,6 @@ async def call_interceptor( |
1428 | 1425 |
|
1429 | 1426 | return await handler(context) |
1430 | 1427 |
|
1431 | | - async def _resolve_workflow_nexus_commands( |
1432 | | - self, |
1433 | | - workflow_cls: type, |
1434 | | - history: list[dict[str, Any]], |
1435 | | - start_input: list[Any], |
1436 | | - task: dict[str, Any], |
1437 | | - *, |
1438 | | - payload_codec: str | None, |
1439 | | - command_codec: str, |
1440 | | - initial_commands: list[Command], |
1441 | | - ) -> list[Command]: |
1442 | | - events = list(history) |
1443 | | - commands: list[Command] = list(initial_commands) |
1444 | | - recorded_commands: list[RecordSideEffect] = [] |
1445 | | - |
1446 | | - for _ in range(_WORKFLOW_TASK_NEXUS_RESOLUTION_LIMIT): |
1447 | | - nexus_commands = [command for command in commands if isinstance(command, NexusServiceCall)] |
1448 | | - if not nexus_commands: |
1449 | | - return recorded_commands + commands |
1450 | | - if len(nexus_commands) != len(commands): |
1451 | | - raise RuntimeError("Nexus service calls must be yielded one at a time") |
1452 | | - |
1453 | | - for command in nexus_commands: |
1454 | | - result = await self.client.execute_nexus_operation( |
1455 | | - command.endpoint_name, |
1456 | | - command.service_name, |
1457 | | - command.operation_name, |
1458 | | - command.arguments, |
1459 | | - mode=command.mode, |
1460 | | - wait_for=command.wait_for, |
1461 | | - wait_timeout_seconds=command.wait_timeout_seconds, |
1462 | | - idempotency_key=command.idempotency_key, |
1463 | | - payload_codec=command.payload_codec, |
1464 | | - caller_namespace=command.caller_namespace, |
1465 | | - target_namespace=command.target_namespace, |
1466 | | - caller_workflow_instance_id=_string_or_none(task.get("workflow_id")), |
1467 | | - caller_workflow_run_id=_string_or_none(task.get("run_id")), |
1468 | | - service_sdk_language=command.service_sdk_language, |
1469 | | - artifact_tuple=command.artifact_tuple, |
1470 | | - published_artifact_worker_execution=command.published_artifact_worker_execution, |
1471 | | - target_workflow_instance_id=command.target_workflow_instance_id, |
1472 | | - target_workflow_run_id=command.target_workflow_run_id, |
1473 | | - connection=command.connection, |
1474 | | - queue=command.queue, |
1475 | | - business_key=command.business_key, |
1476 | | - labels=command.labels, |
1477 | | - memo=command.memo, |
1478 | | - search_attributes=command.search_attributes, |
1479 | | - duplicate_start_policy=command.duplicate_start_policy, |
1480 | | - raise_on_failure=False, |
1481 | | - ) |
1482 | | - recorded_payload = result.to_recorded_payload() |
1483 | | - recorded_commands.append(RecordSideEffect(recorded_payload)) |
1484 | | - events.append({ |
1485 | | - "event_type": "SideEffectRecorded", |
1486 | | - "payload": { |
1487 | | - "payload_codec": command_codec, |
1488 | | - "result": serializer.encode(recorded_payload, codec=command_codec), |
1489 | | - }, |
1490 | | - }) |
1491 | | - |
1492 | | - outcome = replay( |
1493 | | - workflow_cls, |
1494 | | - events, |
1495 | | - start_input, |
1496 | | - workflow_id=task.get("workflow_id"), |
1497 | | - run_id=_string_or_none(task.get("run_id")) or "", |
1498 | | - workflow_command_id=( |
1499 | | - _string_or_none(task.get("workflow_command_id")) |
1500 | | - or _string_or_none(task.get("task_id")) |
1501 | | - ), |
1502 | | - payload_codec=payload_codec, |
1503 | | - external_storage=self.external_storage, |
1504 | | - external_storage_cache=self.external_storage_cache, |
1505 | | - cancel_requested=bool(task.get("cancel_requested", False)), |
1506 | | - ) |
1507 | | - commands = list(outcome.commands) |
1508 | | - |
1509 | | - raise RuntimeError("workflow yielded too many consecutive Nexus service calls") |
1510 | | - |
1511 | 1428 | async def _renew_local_workflow_lease(self, task: dict[str, Any]) -> None: |
1512 | 1429 | if self._cooperative_cancellation_supported and self._local_activity_shutdown.is_set(): |
1513 | 1430 | raise LocalActivityExecutionAborted("worker shutdown abandoned its local workflow claim") |
@@ -2629,45 +2546,7 @@ def execute_local(command: RecordLocalActivity) -> Any: |
2629 | 2546 | log.warning("failed to report replay failure: %s", fe) |
2630 | 2547 | return None |
2631 | 2548 |
|
2632 | | - try: |
2633 | | - workflow_commands = await self._resolve_workflow_nexus_commands( |
2634 | | - cls, |
2635 | | - list(history), |
2636 | | - start_input, |
2637 | | - task, |
2638 | | - payload_codec=codec, |
2639 | | - command_codec=command_codec, |
2640 | | - initial_commands=list(outcome.commands), |
2641 | | - ) |
2642 | | - except Exception as e: |
2643 | | - log.exception("workflow Nexus service call resolution failed") |
2644 | | - last_local = max( |
2645 | | - (index for index, command in enumerate(outcome.commands) |
2646 | | - if isinstance(command, RecordLocalActivity) and command.outcome is not None), |
2647 | | - default=-1, |
2648 | | - ) |
2649 | | - if last_local >= 0: |
2650 | | - workflow_commands = [ |
2651 | | - *outcome.commands[:last_local + 1], |
2652 | | - FailWorkflow( |
2653 | | - f"Nexus resolution after local activity failed: {e}", |
2654 | | - exception_type=type(e).__name__, |
2655 | | - non_retryable=True, |
2656 | | - ), |
2657 | | - ] |
2658 | | - else: |
2659 | | - try: |
2660 | | - await self.client.fail_workflow_task( |
2661 | | - task_id=task_id, |
2662 | | - lease_owner=self.worker_id, |
2663 | | - workflow_task_attempt=attempt, |
2664 | | - message=f"workflow Nexus service call resolution failed: {e}", |
2665 | | - failure_type=type(e).__name__, |
2666 | | - stack_trace=traceback.format_exc(), |
2667 | | - ) |
2668 | | - except Exception as fe: |
2669 | | - log.warning("failed to report workflow Nexus resolution failure: %s", fe) |
2670 | | - return None |
| 2549 | + workflow_commands = list(outcome.commands) |
2671 | 2550 |
|
2672 | 2551 | if ( |
2673 | 2552 | any(isinstance(command, UpsertMemo) for command in workflow_commands) |
|
0 commit comments