Skip to content

Commit 0119147

Browse files
committed
Attach everywhere & add test
1 parent e4bbd54 commit 0119147

File tree

9 files changed

+29
-4
lines changed

9 files changed

+29
-4
lines changed

Diff for: temporalio/activity.py

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class Info:
116116
workflow_namespace: str
117117
workflow_run_id: str
118118
workflow_type: str
119+
priority: temporalio.common.Priority
119120
# TODO(cretz): Consider putting identity on here for "worker_id" for logger?
120121

121122
def _logger_details(self) -> Mapping[str, Any]:

Diff for: temporalio/client.py

+5
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,7 @@ def __init__(
24462446
start_delay: Optional[timedelta] = None,
24472447
rpc_metadata: Mapping[str, str] = {},
24482448
rpc_timeout: Optional[timedelta] = None,
2449+
priority: Optional[temporalio.common.Priority] = None,
24492450
) -> None: ...
24502451

24512452
# Overload for single-param workflow, with_start
@@ -2508,6 +2509,7 @@ def __init__(
25082509
start_delay: Optional[timedelta] = None,
25092510
rpc_metadata: Mapping[str, str] = {},
25102511
rpc_timeout: Optional[timedelta] = None,
2512+
priority: Optional[temporalio.common.Priority] = None,
25112513
) -> None: ...
25122514

25132515
# Overload for string-name workflow, with_start
@@ -2540,6 +2542,7 @@ def __init__(
25402542
start_delay: Optional[timedelta] = None,
25412543
rpc_metadata: Mapping[str, str] = {},
25422544
rpc_timeout: Optional[timedelta] = None,
2545+
priority: Optional[temporalio.common.Priority] = None,
25432546
) -> None: ...
25442547

25452548
def __init__(
@@ -2570,6 +2573,7 @@ def __init__(
25702573
start_delay: Optional[timedelta] = None,
25712574
rpc_metadata: Mapping[str, str] = {},
25722575
rpc_timeout: Optional[timedelta] = None,
2576+
priority: Optional[temporalio.common.Priority] = None,
25732577
stack_level: int = 2,
25742578
) -> None:
25752579
"""Create a WithStartWorkflowOperation.
@@ -2610,6 +2614,7 @@ def __init__(
26102614
ret_type=result_type or result_type_from_run_fn,
26112615
rpc_metadata=rpc_metadata,
26122616
rpc_timeout=rpc_timeout,
2617+
priority=priority,
26132618
)
26142619
self._workflow_handle: Future[WorkflowHandle[SelfType, ReturnType]] = Future()
26152620
self._used = False

Diff for: temporalio/common.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
)
3131

3232
import google.protobuf.internal.containers
33-
from typing_extensions import ClassVar, NamedTuple, Self, TypeAlias, get_origin
33+
from typing_extensions import NamedTuple, Self, TypeAlias, get_origin
3434

3535
import temporalio.api.common.v1
3636
import temporalio.api.enums.v1
@@ -992,6 +992,11 @@ class Priority:
992992
3.
993993
"""
994994

995+
@staticmethod
996+
def from_proto(proto: temporalio.api.common.v1.Priority) -> Priority:
997+
"""Create a Priority instance from the proto object."""
998+
return Priority(priority_key=proto.priority_key)
999+
9951000
def _to_proto(self) -> temporalio.api.common.v1.Priority:
9961001
return temporalio.api.common.v1.Priority(
9971002
priority_key=self.priority_key,

Diff for: temporalio/testing/_activity.py

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
workflow_namespace="default",
4040
workflow_run_id="test-run",
4141
workflow_type="test",
42+
priority=temporalio.common.Priority(priority_key=0),
4243
)
4344

4445

Diff for: temporalio/worker/_activity.py

+1
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ async def _run_activity(
411411
workflow_namespace=start.workflow_namespace,
412412
workflow_run_id=start.workflow_execution.run_id,
413413
workflow_type=start.workflow_type,
414+
priority=temporalio.common.Priority.from_proto(start.priority),
414415
)
415416
running_activity.info = info
416417
input = ExecuteActivityInput(

Diff for: temporalio/worker/_workflow.py

+1
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ def _create_workflow_instance(
404404
),
405405
workflow_id=init.workflow_id,
406406
workflow_type=init.workflow_type,
407+
priority=temporalio.common.Priority.from_proto(init.priority),
407408
)
408409

409410
# Create instance from details

Diff for: temporalio/worker/workflow_sandbox/_runner.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
typed_search_attributes=temporalio.common.TypedSearchAttributes.empty,
4747
workflow_id="sandbox-validate-workflow_id",
4848
workflow_type="sandbox-validate-workflow_type",
49+
priority=temporalio.common.Priority(priority_key=0),
4950
)
5051

5152

Diff for: temporalio/workflow.py

+3
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,9 @@ class Info:
427427
headers: Mapping[str, temporalio.api.common.v1.Payload]
428428
namespace: str
429429
parent: Optional[ParentInfo]
430+
priority: temporalio.common.Priority
431+
"""The priority of this workflow execution. If not set, or this server predates priorities,
432+
then returns a default instance."""
430433
raw_memo: Mapping[str, temporalio.api.common.v1.Payload]
431434
retry_policy: Optional[temporalio.common.RetryPolicy]
432435
run_id: str

Diff for: tests/worker/test_workflow.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -6034,9 +6034,9 @@ async def _do_first_completion_command_is_honored_test(
60346034
result = await handle.result()
60356035
except WorkflowFailureError as err:
60366036
if main_workflow_returns_before_signal_completions:
6037-
assert (
6038-
False
6039-
), "Expected no error due to main workflow coroutine returning first"
6037+
assert False, (
6038+
"Expected no error due to main workflow coroutine returning first"
6039+
)
60406040
else:
60416041
assert str(err.cause).startswith("Client should see this error")
60426042
else:
@@ -6993,10 +6993,17 @@ async def test_update_handler_semaphore_acquisition_respects_timeout(
69936993
)
69946994

69956995

6996+
@activity.defn
6997+
async def check_priority_activity(should_have_priorty: int) -> str:
6998+
assert activity.info().priority.priority_key == should_have_priorty
6999+
return "Done!"
7000+
7001+
69967002
@workflow.defn
69977003
class WorkflowUsingPriorities:
69987004
@workflow.run
69997005
async def run(self, name: str) -> str:
7006+
assert workflow.info().priority.priority_key == 1
70007007
await workflow.execute_child_workflow(
70017008
HelloWorkflow.run, name, priority=Priority(priority_key=4)
70027009
)

0 commit comments

Comments
 (0)