@@ -255,49 +255,43 @@ async def _handle_activation(
255
255
)
256
256
completion .successful .SetInParent ()
257
257
try :
258
- # Decode the activation if there's a codec and not cache remove job
259
-
260
258
if LOG_PROTOS :
261
259
logger .debug ("Received workflow activation:\n %s" , act )
262
260
263
- # If the workflow is not running yet, create it
264
261
workflow = self ._running_workflows .get (act .run_id )
265
-
266
- if data_converter .payload_codec :
267
- await temporalio .bridge .worker .decode_activation (
268
- act ,
269
- data_converter .payload_codec ,
270
- decode_headers = self ._encode_headers ,
271
- )
272
262
if not workflow :
273
- # Must have a initialize job to create instance
274
263
if not init_job :
275
264
raise RuntimeError (
276
265
"Missing initialize workflow, workflow could have unexpectedly been removed from cache"
277
266
)
278
- data_converter = self ._data_converter ._with_context (
279
- temporalio .converter .WorkflowSerializationContext (
280
- namespace = self ._namespace ,
281
- workflow_id = init_job .workflow_id ,
267
+ workflow_id = init_job .workflow_id
268
+ else :
269
+ workflow_id = workflow .workflow_id
270
+ if init_job :
271
+ # Should never happen
272
+ logger .warning (
273
+ "Cache already exists for activation with initialize job"
282
274
)
283
- )
284
- workflow = _RunningWorkflow (
285
- self ._create_workflow_instance (act , init_job ),
286
- init_job .workflow_id ,
287
- )
288
- self ._running_workflows [act .run_id ] = workflow
289
- elif init_job :
290
- # This should never happen
291
- logger .warning (
292
- "Cache already exists for activation with initialize job"
293
- )
294
275
295
276
data_converter = self ._data_converter ._with_context (
296
277
temporalio .converter .WorkflowSerializationContext (
297
278
namespace = self ._namespace ,
298
- workflow_id = workflow . workflow_id ,
279
+ workflow_id = workflow_id ,
299
280
)
300
281
)
282
+ if data_converter .payload_codec :
283
+ await temporalio .bridge .worker .decode_activation (
284
+ act ,
285
+ data_converter .payload_codec ,
286
+ decode_headers = self ._encode_headers ,
287
+ )
288
+ if not workflow :
289
+ assert init_job
290
+ workflow = _RunningWorkflow (
291
+ self ._create_workflow_instance (act , init_job ),
292
+ workflow_id ,
293
+ )
294
+ self ._running_workflows [act .run_id ] = workflow
301
295
302
296
# Run activation in separate thread so we can check if it's
303
297
# deadlocked
@@ -337,7 +331,6 @@ async def _handle_activation(
337
331
"Failed handling activation on workflow with run ID %s" , act .run_id
338
332
)
339
333
340
- # Set completion failure
341
334
completion .failed .failure .SetInParent ()
342
335
try :
343
336
data_converter .failure_converter .to_failure (
@@ -354,10 +347,9 @@ async def _handle_activation(
354
347
f"Failed converting activation exception: { inner_err } "
355
348
)
356
349
357
- # Always set the run ID on the completion
358
350
completion .run_id = act .run_id
359
351
360
- # Encode the completion if there's a codec and not cache remove job
352
+ # Encode completion
361
353
if data_converter .payload_codec :
362
354
try :
363
355
await temporalio .bridge .worker .encode_completion (
0 commit comments