-
Notifications
You must be signed in to change notification settings - Fork 147
Standalone activity #1138
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
Closed
Closed
Standalone activity #1138
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e0d31de
Update core
dandavison 08dea1e
uv run poe gen-protos-docker
dandavison 72c7184
Standalone activity prototype
dandavison 83b11e7
Modernize type annotations
dandavison ad5d081
Conform standalone activity API to cross-language design spec
dandavison 904c04f
Implement the rest of the spec
dandavison 2843bee
Merge remote-tracking branch 'remotes/origin/main' into standalone-ac…
cretz 0be7b55
Fix Core submodule version
cretz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,16 +104,25 @@ class Info: | |
| heartbeat_details: Sequence[Any] | ||
| heartbeat_timeout: timedelta | None | ||
| is_local: bool | ||
| namespace: str | ||
| schedule_to_close_timeout: timedelta | None | ||
| scheduled_time: datetime | ||
| start_to_close_timeout: timedelta | None | ||
| started_time: datetime | ||
| task_queue: str | ||
| task_token: bytes | ||
| workflow_id: str | ||
| workflow_namespace: str | ||
| workflow_run_id: str | ||
| workflow_type: str | ||
| workflow_id: str | None | ||
| """ID of the workflow. None if the activity was not started by a workflow.""" | ||
| workflow_namespace: str | None | ||
| """Namespace of the workflow. None if the activity was not started by a workflow. | ||
|
|
||
| .. deprecated:: | ||
| Use :py:attr:`namespace` instead. | ||
| """ | ||
| workflow_run_id: str | None | ||
| """Run ID of the workflow. None if the activity was not started by a workflow.""" | ||
| workflow_type: str | None | ||
| """Type of the workflow. None if the activity was not started by a workflow.""" | ||
| priority: temporalio.common.Priority | ||
| retry_policy: temporalio.common.RetryPolicy | None | ||
| """The retry policy of this activity. | ||
|
|
@@ -122,14 +131,22 @@ class Info: | |
| If the value is None, it means the server didn't send information about retry policy (e.g. due to old server | ||
| version), but it may still be defined server-side.""" | ||
|
|
||
| activity_run_id: str | None = None | ||
| """Run ID of this activity. None for workflow activities.""" | ||
|
|
||
| @property | ||
| def in_workflow(self) -> bool: | ||
| """Was this activity started by a workflow?""" | ||
| return self.workflow_id is not None | ||
|
|
||
| # TODO(cretz): Consider putting identity on here for "worker_id" for logger? | ||
|
|
||
| def _logger_details(self) -> Mapping[str, Any]: | ||
| return { | ||
| "activity_id": self.activity_id, | ||
| "activity_type": self.activity_type, | ||
| "attempt": self.attempt, | ||
| "namespace": self.workflow_namespace, | ||
| "namespace": self.namespace, | ||
| "task_queue": self.task_queue, | ||
| "workflow_id": self.workflow_id, | ||
| "workflow_run_id": self.workflow_run_id, | ||
|
|
@@ -238,7 +255,7 @@ def metric_meter(self) -> temporalio.common.MetricMeter: | |
| info = self.info() | ||
| self._metric_meter = self.runtime_metric_meter.with_additional_attributes( | ||
| { | ||
| "namespace": info.workflow_namespace, | ||
| "namespace": info.namespace, | ||
| "task_queue": info.task_queue, | ||
| "activity_type": info.activity_type, | ||
| } | ||
|
|
@@ -577,6 +594,20 @@ def must_from_callable(fn: Callable) -> _Definition: | |
| f"Activity {fn_name} missing attributes, was it decorated with @activity.defn?" | ||
| ) | ||
|
|
||
| @classmethod | ||
| def get_name_and_result_type( | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're extracting this common logic out of |
||
| cls, name_or_run_fn: str | Callable[..., Any] | ||
| ) -> tuple[str, type | None]: | ||
| if isinstance(name_or_run_fn, str): | ||
| return name_or_run_fn, None | ||
| elif callable(name_or_run_fn): | ||
| defn = cls.must_from_callable(name_or_run_fn) | ||
| if not defn.name: | ||
| raise ValueError(f"Activity {name_or_run_fn} definition has no name") | ||
| return defn.name, defn.ret_type | ||
| else: | ||
| raise TypeError("Activity must be a string or callable") # type:ignore[reportUnreachable] | ||
|
|
||
| @staticmethod | ||
| def _apply_to_callable( | ||
| fn: Callable, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should go ahead and put here the expected changes to activity runtime. Specifically I assume all
workflow_-prefixed fields ofInfowill become optional. I would also recommend either a "kind" enumerate for activities, or add anis_standaloneakin tois_localso users can know it's not the traditional activity.