Skip to content

Commit 1331902

Browse files
committed
start workflow job -> initialize workflow
1 parent 78ed565 commit 1331902

File tree

4 files changed

+51
-49
lines changed

4 files changed

+51
-49
lines changed

temporalio/bridge/worker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,11 @@ async def decode_activation(
321321
await codec.decode_failure(job.resolve_signal_external_workflow.failure)
322322
elif job.HasField("signal_workflow"):
323323
await _decode_payloads(job.signal_workflow.input, codec)
324-
elif job.HasField("start_workflow"):
325-
await _decode_payloads(job.start_workflow.arguments, codec)
326-
if job.start_workflow.HasField("continued_failure"):
327-
await codec.decode_failure(job.start_workflow.continued_failure)
328-
for val in job.start_workflow.memo.fields.values():
324+
elif job.HasField("initialize_workflow"):
325+
await _decode_payloads(job.initialize_workflow.arguments, codec)
326+
if job.initialize_workflow.HasField("continued_failure"):
327+
await codec.decode_failure(job.initialize_workflow.continued_failure)
328+
for val in job.initialize_workflow.memo.fields.values():
329329
# This uses API payload not bridge payload
330330
new_payload = (await codec.decode([val]))[0]
331331
val.metadata.clear()

temporalio/worker/_workflow.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,12 @@ async def _handle_activation(
206206

207207
# Extract a couple of jobs from the activation
208208
cache_remove_job = None
209-
start_job = None
209+
init_job = None
210210
for job in act.jobs:
211211
if job.HasField("remove_from_cache"):
212212
cache_remove_job = job.remove_from_cache
213-
elif job.HasField("start_workflow"):
214-
start_job = job.start_workflow
213+
elif job.HasField("initialize_workflow"):
214+
init_job = job.initialize_workflow
215215

216216
# Build default success completion (e.g. remove-job-only activations)
217217
completion = (
@@ -235,16 +235,16 @@ async def _handle_activation(
235235
if not cache_remove_job or not self._disable_safe_eviction:
236236
workflow = self._running_workflows.get(act.run_id)
237237
if not workflow and not cache_remove_job:
238-
# Must have a start job to create instance
239-
if not start_job:
238+
# Must have a initialize job to create instance
239+
if not init_job:
240240
raise RuntimeError(
241-
"Missing start workflow, workflow could have unexpectedly been removed from cache"
241+
"Missing initialize workflow, workflow could have unexpectedly been removed from cache"
242242
)
243-
workflow = self._create_workflow_instance(act, start_job)
243+
workflow = self._create_workflow_instance(act, init_job)
244244
self._running_workflows[act.run_id] = workflow
245-
elif start_job:
245+
elif init_job:
246246
# This should never happen
247-
logger.warn("Cache already exists for activation with start job")
247+
logger.warn("Cache already exists for activation with initialize job")
248248

249249
# Run activation in separate thread so we can check if it's
250250
# deadlocked
@@ -354,54 +354,54 @@ async def _handle_activation(
354354
def _create_workflow_instance(
355355
self,
356356
act: temporalio.bridge.proto.workflow_activation.WorkflowActivation,
357-
start: temporalio.bridge.proto.workflow_activation.StartWorkflow,
357+
init: temporalio.bridge.proto.workflow_activation.InitializeWorkflow,
358358
) -> WorkflowInstance:
359359
# Get the definition
360-
defn = self._workflows.get(start.workflow_type, self._dynamic_workflow)
360+
defn = self._workflows.get(init.workflow_type, self._dynamic_workflow)
361361
if not defn:
362362
workflow_names = ", ".join(sorted(self._workflows.keys()))
363363
raise temporalio.exceptions.ApplicationError(
364-
f"Workflow class {start.workflow_type} is not registered on this worker, available workflows: {workflow_names}",
364+
f"Workflow class {init.workflow_type} is not registered on this worker, available workflows: {workflow_names}",
365365
type="NotFoundError",
366366
)
367367

368368
# Build info
369369
parent: Optional[temporalio.workflow.ParentInfo] = None
370-
if start.HasField("parent_workflow_info"):
370+
if init.HasField("parent_workflow_info"):
371371
parent = temporalio.workflow.ParentInfo(
372-
namespace=start.parent_workflow_info.namespace,
373-
run_id=start.parent_workflow_info.run_id,
374-
workflow_id=start.parent_workflow_info.workflow_id,
372+
namespace=init.parent_workflow_info.namespace,
373+
run_id=init.parent_workflow_info.run_id,
374+
workflow_id=init.parent_workflow_info.workflow_id,
375375
)
376376
info = temporalio.workflow.Info(
377-
attempt=start.attempt,
378-
continued_run_id=start.continued_from_execution_run_id or None,
379-
cron_schedule=start.cron_schedule or None,
380-
execution_timeout=start.workflow_execution_timeout.ToTimedelta()
381-
if start.HasField("workflow_execution_timeout")
377+
attempt=init.attempt,
378+
continued_run_id=init.continued_from_execution_run_id or None,
379+
cron_schedule=init.cron_schedule or None,
380+
execution_timeout=init.workflow_execution_timeout.ToTimedelta()
381+
if init.HasField("workflow_execution_timeout")
382382
else None,
383-
headers=dict(start.headers),
383+
headers=dict(init.headers),
384384
namespace=self._namespace,
385385
parent=parent,
386-
raw_memo=dict(start.memo.fields),
387-
retry_policy=temporalio.common.RetryPolicy.from_proto(start.retry_policy)
388-
if start.HasField("retry_policy")
386+
raw_memo=dict(init.memo.fields),
387+
retry_policy=temporalio.common.RetryPolicy.from_proto(init.retry_policy)
388+
if init.HasField("retry_policy")
389389
else None,
390390
run_id=act.run_id,
391-
run_timeout=start.workflow_run_timeout.ToTimedelta()
392-
if start.HasField("workflow_run_timeout")
391+
run_timeout=init.workflow_run_timeout.ToTimedelta()
392+
if init.HasField("workflow_run_timeout")
393393
else None,
394394
search_attributes=temporalio.converter.decode_search_attributes(
395-
start.search_attributes
395+
init.search_attributes
396396
),
397397
start_time=act.timestamp.ToDatetime().replace(tzinfo=timezone.utc),
398398
task_queue=self._task_queue,
399-
task_timeout=start.workflow_task_timeout.ToTimedelta(),
399+
task_timeout=init.workflow_task_timeout.ToTimedelta(),
400400
typed_search_attributes=temporalio.converter.decode_typed_search_attributes(
401-
start.search_attributes
401+
init.search_attributes
402402
),
403-
workflow_id=start.workflow_id,
404-
workflow_type=start.workflow_type,
403+
workflow_id=init.workflow_id,
404+
workflow_type=init.workflow_type,
405405
)
406406

407407
# Create instance from details
@@ -411,7 +411,7 @@ def _create_workflow_instance(
411411
interceptor_classes=self._interceptor_classes,
412412
defn=defn,
413413
info=info,
414-
randomness_seed=start.randomness_seed,
414+
randomness_seed=init.randomness_seed,
415415
extern_functions=self._extern_functions,
416416
disable_eager_activity_execution=self._disable_eager_activity_execution,
417417
worker_level_failure_exception_types=self._workflow_failure_exception_types,

temporalio/worker/_workflow_instance.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def activate(
354354
elif job.HasField("signal_workflow") or job.HasField("do_update"):
355355
job_sets[1].append(job)
356356
elif not job.HasField("query_workflow"):
357-
if job.HasField("start_workflow"):
358-
start_job = job.start_workflow
357+
if job.HasField("initialize_workflow"):
358+
start_job = job.initialize_workflow
359359
job_sets[2].append(job)
360360
else:
361361
job_sets[3].append(job)
@@ -477,8 +477,8 @@ def _apply(
477477
)
478478
elif job.HasField("signal_workflow"):
479479
self._apply_signal_workflow(job.signal_workflow)
480-
elif job.HasField("start_workflow"):
481-
self._apply_start_workflow(job.start_workflow)
480+
elif job.HasField("initialize_workflow"):
481+
self._apply_initialize_workflow(job.initialize_workflow)
482482
elif job.HasField("update_random_seed"):
483483
self._apply_update_random_seed(job.update_random_seed)
484484
else:
@@ -847,8 +847,8 @@ def _apply_signal_workflow(
847847
return
848848
self._process_signal_job(signal_defn, job)
849849

850-
def _apply_start_workflow(
851-
self, job: temporalio.bridge.proto.workflow_activation.StartWorkflow
850+
def _apply_initialize_workflow(
851+
self, job: temporalio.bridge.proto.workflow_activation.InitializeWorkflow
852852
) -> None:
853853
# Async call to run on the scheduler thread. This will be wrapped in
854854
# another function which applies exception handling.
@@ -886,14 +886,14 @@ def _apply_update_random_seed(
886886
self._random.seed(job.randomness_seed)
887887

888888
def _make_workflow_input(
889-
self, start_job: temporalio.bridge.proto.workflow_activation.StartWorkflow
889+
self, init_job: temporalio.bridge.proto.workflow_activation.InitializeWorkflow
890890
) -> ExecuteWorkflowInput:
891891
# Set arg types, using raw values for dynamic
892892
arg_types = self._defn.arg_types
893893
if not self._defn.name:
894894
# Dynamic is just the raw value for each input value
895-
arg_types = [temporalio.common.RawValue] * len(start_job.arguments)
896-
args = self._convert_payloads(start_job.arguments, arg_types)
895+
arg_types = [temporalio.common.RawValue] * len(init_job.arguments)
896+
args = self._convert_payloads(init_job.arguments, arg_types)
897897
# Put args in a list if dynamic
898898
if not self._defn.name:
899899
args = [args]
@@ -903,7 +903,7 @@ def _make_workflow_input(
903903
# TODO(cretz): Remove cast when https://github.com/python/mypy/issues/5485 fixed
904904
run_fn=cast(Callable[..., Awaitable[Any]], self._defn.run_fn),
905905
args=args,
906-
headers=start_job.headers,
906+
headers=init_job.headers,
907907
)
908908

909909
#### _Runtime direct workflow call overrides ####

tests/worker/test_workflow.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1553,7 +1553,9 @@ async def test_workflow_with_custom_runner(client: Client):
15531553
)
15541554
assert result == "Hello, Temporal!"
15551555
# Confirm first activation and last completion
1556-
assert runner._pairs[0][0].jobs[0].start_workflow.workflow_type == "HelloWorkflow"
1556+
assert (
1557+
runner._pairs[0][0].jobs[0].initialize_workflow.workflow_type == "HelloWorkflow"
1558+
)
15571559
assert (
15581560
runner._pairs[-1][-1]
15591561
.successful.commands[0]

0 commit comments

Comments
 (0)