11# This file is generated by gen_payload_visitor.py. Changes should be made there.
22import abc
3- from typing import Any , MutableSequence
3+ import contextvars
4+ from typing import Any , MutableSequence , Optional
45
56from temporalio .api .common .v1 .message_pb2 import Payload
67
8+ # Current workflow command sequence number
9+ current_command_seq : contextvars .ContextVar [Optional [int ]] = contextvars .ContextVar (
10+ "current_command_seq" , default = None
11+ )
12+
713
814class VisitorFunctions (abc .ABC ):
915 """Set of functions which can be called by the visitor.
@@ -247,35 +253,69 @@ async def _visit_coresdk_workflow_activation_WorkflowActivationJob(self, fs, o):
247253 fs , o .signal_workflow
248254 )
249255 elif o .HasField ("resolve_activity" ):
250- await self ._visit_coresdk_workflow_activation_ResolveActivity (
251- fs , o .resolve_activity
252- )
256+ token = current_command_seq .set (o .resolve_activity .seq )
257+ try :
258+ await self ._visit_coresdk_workflow_activation_ResolveActivity (
259+ fs , o .resolve_activity
260+ )
261+ finally :
262+ current_command_seq .reset (token )
253263 elif o .HasField ("resolve_child_workflow_execution_start" ):
254- await self . _visit_coresdk_workflow_activation_ResolveChildWorkflowExecutionStart (
255- fs , o .resolve_child_workflow_execution_start
264+ token = current_command_seq . set (
265+ o .resolve_child_workflow_execution_start . seq
256266 )
267+ try :
268+ await self ._visit_coresdk_workflow_activation_ResolveChildWorkflowExecutionStart (
269+ fs , o .resolve_child_workflow_execution_start
270+ )
271+ finally :
272+ current_command_seq .reset (token )
257273 elif o .HasField ("resolve_child_workflow_execution" ):
258- await self ._visit_coresdk_workflow_activation_ResolveChildWorkflowExecution (
259- fs , o .resolve_child_workflow_execution
260- )
274+ token = current_command_seq .set (o .resolve_child_workflow_execution .seq )
275+ try :
276+ await self ._visit_coresdk_workflow_activation_ResolveChildWorkflowExecution (
277+ fs , o .resolve_child_workflow_execution
278+ )
279+ finally :
280+ current_command_seq .reset (token )
261281 elif o .HasField ("resolve_signal_external_workflow" ):
262- await self ._visit_coresdk_workflow_activation_ResolveSignalExternalWorkflow (
263- fs , o .resolve_signal_external_workflow
264- )
282+ token = current_command_seq .set (o .resolve_signal_external_workflow .seq )
283+ try :
284+ await self ._visit_coresdk_workflow_activation_ResolveSignalExternalWorkflow (
285+ fs , o .resolve_signal_external_workflow
286+ )
287+ finally :
288+ current_command_seq .reset (token )
265289 elif o .HasField ("resolve_request_cancel_external_workflow" ):
266- await self . _visit_coresdk_workflow_activation_ResolveRequestCancelExternalWorkflow (
267- fs , o .resolve_request_cancel_external_workflow
290+ token = current_command_seq . set (
291+ o .resolve_request_cancel_external_workflow . seq
268292 )
293+ try :
294+ await self ._visit_coresdk_workflow_activation_ResolveRequestCancelExternalWorkflow (
295+ fs , o .resolve_request_cancel_external_workflow
296+ )
297+ finally :
298+ current_command_seq .reset (token )
269299 elif o .HasField ("do_update" ):
270300 await self ._visit_coresdk_workflow_activation_DoUpdate (fs , o .do_update )
271301 elif o .HasField ("resolve_nexus_operation_start" ):
272- await self ._visit_coresdk_workflow_activation_ResolveNexusOperationStart (
273- fs , o .resolve_nexus_operation_start
274- )
302+ token = current_command_seq .set (o .resolve_nexus_operation_start .seq )
303+ try :
304+ await (
305+ self ._visit_coresdk_workflow_activation_ResolveNexusOperationStart (
306+ fs , o .resolve_nexus_operation_start
307+ )
308+ )
309+ finally :
310+ current_command_seq .reset (token )
275311 elif o .HasField ("resolve_nexus_operation" ):
276- await self ._visit_coresdk_workflow_activation_ResolveNexusOperation (
277- fs , o .resolve_nexus_operation
278- )
312+ token = current_command_seq .set (o .resolve_nexus_operation .seq )
313+ try :
314+ await self ._visit_coresdk_workflow_activation_ResolveNexusOperation (
315+ fs , o .resolve_nexus_operation
316+ )
317+ finally :
318+ current_command_seq .reset (token )
279319
280320 async def _visit_coresdk_workflow_activation_WorkflowActivation (self , fs , o ):
281321 for v in o .jobs :
@@ -371,9 +411,13 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(self, fs, o):
371411 if o .HasField ("user_metadata" ):
372412 await self ._visit_temporal_api_sdk_v1_UserMetadata (fs , o .user_metadata )
373413 if o .HasField ("schedule_activity" ):
374- await self ._visit_coresdk_workflow_commands_ScheduleActivity (
375- fs , o .schedule_activity
376- )
414+ token = current_command_seq .set (o .schedule_activity .seq )
415+ try :
416+ await self ._visit_coresdk_workflow_commands_ScheduleActivity (
417+ fs , o .schedule_activity
418+ )
419+ finally :
420+ current_command_seq .reset (token )
377421 elif o .HasField ("respond_to_query" ):
378422 await self ._visit_coresdk_workflow_commands_QueryResult (
379423 fs , o .respond_to_query
@@ -391,17 +435,29 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(self, fs, o):
391435 fs , o .continue_as_new_workflow_execution
392436 )
393437 elif o .HasField ("start_child_workflow_execution" ):
394- await self ._visit_coresdk_workflow_commands_StartChildWorkflowExecution (
395- fs , o .start_child_workflow_execution
396- )
438+ token = current_command_seq .set (o .start_child_workflow_execution .seq )
439+ try :
440+ await self ._visit_coresdk_workflow_commands_StartChildWorkflowExecution (
441+ fs , o .start_child_workflow_execution
442+ )
443+ finally :
444+ current_command_seq .reset (token )
397445 elif o .HasField ("signal_external_workflow_execution" ):
398- await self ._visit_coresdk_workflow_commands_SignalExternalWorkflowExecution (
399- fs , o .signal_external_workflow_execution
400- )
446+ token = current_command_seq .set (o .signal_external_workflow_execution .seq )
447+ try :
448+ await self ._visit_coresdk_workflow_commands_SignalExternalWorkflowExecution (
449+ fs , o .signal_external_workflow_execution
450+ )
451+ finally :
452+ current_command_seq .reset (token )
401453 elif o .HasField ("schedule_local_activity" ):
402- await self ._visit_coresdk_workflow_commands_ScheduleLocalActivity (
403- fs , o .schedule_local_activity
404- )
454+ token = current_command_seq .set (o .schedule_local_activity .seq )
455+ try :
456+ await self ._visit_coresdk_workflow_commands_ScheduleLocalActivity (
457+ fs , o .schedule_local_activity
458+ )
459+ finally :
460+ current_command_seq .reset (token )
405461 elif o .HasField ("upsert_workflow_search_attributes" ):
406462 await self ._visit_coresdk_workflow_commands_UpsertWorkflowSearchAttributes (
407463 fs , o .upsert_workflow_search_attributes
@@ -415,9 +471,13 @@ async def _visit_coresdk_workflow_commands_WorkflowCommand(self, fs, o):
415471 fs , o .update_response
416472 )
417473 elif o .HasField ("schedule_nexus_operation" ):
418- await self ._visit_coresdk_workflow_commands_ScheduleNexusOperation (
419- fs , o .schedule_nexus_operation
420- )
474+ token = current_command_seq .set (o .schedule_nexus_operation .seq )
475+ try :
476+ await self ._visit_coresdk_workflow_commands_ScheduleNexusOperation (
477+ fs , o .schedule_nexus_operation
478+ )
479+ finally :
480+ current_command_seq .reset (token )
421481
422482 async def _visit_coresdk_workflow_completion_Success (self , fs , o ):
423483 for v in o .commands :
0 commit comments