Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Interrupt heartbeating activity on pause #854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
37 changes: 37 additions & 0 deletions temporalio/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
overload,
)

import temporalio.bridge
import temporalio.bridge.proto
import temporalio.bridge.proto.activity_task
import temporalio.common
import temporalio.converter

Expand Down Expand Up @@ -135,6 +138,34 @@ def _logger_details(self) -> Mapping[str, Any]:
_current_context: contextvars.ContextVar[_Context] = contextvars.ContextVar("activity")


@dataclass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be frozen

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We mutate the fields in this object to reflect changes across running activity & _context

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to frozen class + holder

class _ActivityCancellationDetailsHolder:
details: Optional[ActivityCancellationDetails] = None


@dataclass(frozen=True)
class ActivityCancellationDetails:
"""Provides the reasons for the activity's cancellation. Cancellation details are set once and do not change once set."""

not_found: bool = False
cancel_requested: bool = False
paused: bool = False
timed_out: bool = False
worker_shutdown: bool = False

@staticmethod
def _from_proto(
proto: temporalio.bridge.proto.activity_task.ActivityCancellationDetails,
) -> ActivityCancellationDetails:
return ActivityCancellationDetails(
not_found=proto.is_not_found,
cancel_requested=proto.is_cancelled,
paused=proto.is_paused,
timed_out=proto.is_timed_out,
worker_shutdown=proto.is_worker_shutdown,
)


@dataclass
class _Context:
info: Callable[[], Info]
Expand All @@ -148,6 +179,7 @@ class _Context:
temporalio.converter.PayloadConverter,
]
runtime_metric_meter: Optional[temporalio.common.MetricMeter]
cancellation_details: _ActivityCancellationDetailsHolder
_logger_details: Optional[Mapping[str, Any]] = None
_payload_converter: Optional[temporalio.converter.PayloadConverter] = None
_metric_meter: Optional[temporalio.common.MetricMeter] = None
Expand Down Expand Up @@ -260,6 +292,11 @@ def info() -> Info:
return _Context.current().info()


def cancellation_details() -> Optional[ActivityCancellationDetails]:
"""Cancellation details of the current activity, if any. Once set, cancellation details do not change."""
return _Context.current().cancellation_details.details


def heartbeat(*details: Any) -> None:
"""Send a heartbeat for the current activity.

Expand Down
2 changes: 2 additions & 0 deletions temporalio/api/batch/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
BatchOperationReset,
BatchOperationSignal,
BatchOperationTermination,
BatchOperationTriggerWorkflowRule,
BatchOperationUnpauseActivities,
BatchOperationUpdateWorkflowExecutionOptions,
)
Expand All @@ -16,6 +17,7 @@
"BatchOperationReset",
"BatchOperationSignal",
"BatchOperationTermination",
"BatchOperationTriggerWorkflowRule",
"BatchOperationUnpauseActivities",
"BatchOperationUpdateWorkflowExecutionOptions",
]
53 changes: 36 additions & 17 deletions temporalio/api/batch/v1/message_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions temporalio/api/batch/v1/message_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import google.protobuf.timestamp_pb2
import temporalio.api.common.v1.message_pb2
import temporalio.api.enums.v1.batch_operation_pb2
import temporalio.api.enums.v1.reset_pb2
import temporalio.api.rules.v1.message_pb2
import temporalio.api.workflow.v1.message_pb2

if sys.version_info >= (3, 8):
Expand Down Expand Up @@ -392,3 +393,43 @@ class BatchOperationUnpauseActivities(google.protobuf.message.Message):
) -> typing_extensions.Literal["type", "match_all"] | None: ...

global___BatchOperationUnpauseActivities = BatchOperationUnpauseActivities

class BatchOperationTriggerWorkflowRule(google.protobuf.message.Message):
"""BatchOperationTriggerWorkflowRule sends TriggerWorkflowRule requests to batch workflows."""

DESCRIPTOR: google.protobuf.descriptor.Descriptor

IDENTITY_FIELD_NUMBER: builtins.int
ID_FIELD_NUMBER: builtins.int
SPEC_FIELD_NUMBER: builtins.int
identity: builtins.str
"""The identity of the worker/client."""
id: builtins.str
"""ID of existing rule."""
@property
def spec(self) -> temporalio.api.rules.v1.message_pb2.WorkflowRuleSpec:
"""Rule specification to be applied to the workflow without creating a new rule."""
def __init__(
self,
*,
identity: builtins.str = ...,
id: builtins.str = ...,
spec: temporalio.api.rules.v1.message_pb2.WorkflowRuleSpec | None = ...,
) -> None: ...
def HasField(
self,
field_name: typing_extensions.Literal[
"id", b"id", "rule", b"rule", "spec", b"spec"
],
) -> builtins.bool: ...
def ClearField(
self,
field_name: typing_extensions.Literal[
"id", b"id", "identity", b"identity", "rule", b"rule", "spec", b"spec"
],
) -> None: ...
def WhichOneof(
self, oneof_group: typing_extensions.Literal["rule", b"rule"]
) -> typing_extensions.Literal["id", "spec"] | None: ...

global___BatchOperationTriggerWorkflowRule = BatchOperationTriggerWorkflowRule
4 changes: 4 additions & 0 deletions temporalio/api/enums/v1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from .batch_operation_pb2 import BatchOperationState, BatchOperationType
from .command_type_pb2 import CommandType
from .common_pb2 import (
ApplicationErrorCategory,
CallbackState,
EncodingType,
IndexedValueType,
NexusOperationCancellationState,
PendingNexusOperationState,
Severity,
WorkflowRuleActionScope,
)
from .deployment_pb2 import (
DeploymentReachability,
Expand Down Expand Up @@ -50,6 +52,7 @@
)

__all__ = [
"ApplicationErrorCategory",
"ArchivalState",
"BatchOperationState",
"BatchOperationType",
Expand Down Expand Up @@ -96,5 +99,6 @@
"WorkflowExecutionStatus",
"WorkflowIdConflictPolicy",
"WorkflowIdReusePolicy",
"WorkflowRuleActionScope",
"WorkflowTaskFailedCause",
]
15 changes: 14 additions & 1 deletion temporalio/api/enums/v1/common_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading