-
Notifications
You must be signed in to change notification settings - Fork 103
Nexus worker and workflow-backed operations #813
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
base: main
Are you sure you want to change the base?
Changes from all commits
1e53211
6ec8782
9ca2b53
f8bd453
873a866
f25a06e
a45c258
7760057
b9158f5
586a6ec
181266a
b5235e4
7d145fa
60a207d
d032b74
4213f6b
1f132bb
6fc7b7f
43aab59
1c3780a
8de7772
f1e3568
071ebbd
0a527dc
0f22e1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
from datetime import datetime, timedelta | ||
from enum import Enum, IntEnum | ||
from enum import IntEnum | ||
from typing import ( | ||
Any, | ||
Callable, | ||
|
@@ -197,6 +197,37 @@ def __setstate__(self, state: object) -> None: | |
) | ||
|
||
|
||
@dataclass(frozen=True) | ||
class NexusCompletionCallback: | ||
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. I wonder if this is best in the |
||
"""Nexus callback to attach to events such as workflow completion.""" | ||
|
||
url: str | ||
"""Callback URL.""" | ||
|
||
header: Mapping[str, str] | ||
"""Header to attach to callback request.""" | ||
|
||
|
||
@dataclass(frozen=True) | ||
class WorkflowEventLink: | ||
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. Is this class used? |
||
"""A link to a history event that can be attached to a different history event.""" | ||
|
||
namespace: str | ||
"""Namespace of the workflow to link to.""" | ||
|
||
workflow_id: str | ||
"""ID of the workflow to link to.""" | ||
|
||
run_id: str | ||
"""Run ID of the workflow to link to.""" | ||
|
||
event_type: temporalio.api.enums.v1.EventType | ||
"""Type of the event to link to.""" | ||
|
||
event_id: int | ||
"""ID of the event to link to.""" | ||
|
||
|
||
# We choose to make this a list instead of an sequence so we can catch if people | ||
# are not sending lists each time but maybe accidentally sending a string (which | ||
# is a sequence) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -911,6 +911,12 @@ def _error_to_failure( | |
failure.child_workflow_execution_failure_info.retry_state = ( | ||
temporalio.api.enums.v1.RetryState.ValueType(error.retry_state or 0) | ||
) | ||
# TODO(nexus-prerelease): test coverage for this | ||
elif isinstance(error, temporalio.exceptions.NexusOperationError): | ||
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. For symmetry reasons, I suspect we also need to convert |
||
failure.nexus_operation_execution_failure_info.SetInParent() | ||
failure.nexus_operation_execution_failure_info.operation_token = ( | ||
error.operation_token | ||
) | ||
|
||
def from_failure( | ||
self, | ||
|
@@ -1006,6 +1012,26 @@ def from_failure( | |
if child_info.retry_state | ||
else None, | ||
) | ||
elif failure.HasField("nexus_handler_failure_info"): | ||
nexus_handler_failure_info = failure.nexus_handler_failure_info | ||
err = temporalio.exceptions.NexusHandlerError( | ||
failure.message or "Nexus handler error", | ||
type=nexus_handler_failure_info.type, | ||
retryable={ | ||
temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_RETRYABLE: True, | ||
temporalio.api.enums.v1.NexusHandlerErrorRetryBehavior.NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_NON_RETRYABLE: False, | ||
}.get(nexus_handler_failure_info.retry_behavior), | ||
) | ||
elif failure.HasField("nexus_operation_execution_failure_info"): | ||
nexus_op_failure_info = failure.nexus_operation_execution_failure_info | ||
err = temporalio.exceptions.NexusOperationError( | ||
failure.message or "Nexus operation error", | ||
scheduled_event_id=nexus_op_failure_info.scheduled_event_id, | ||
endpoint=nexus_op_failure_info.endpoint, | ||
service=nexus_op_failure_info.service, | ||
operation=nexus_op_failure_info.operation, | ||
operation_token=nexus_op_failure_info.operation_token, | ||
) | ||
else: | ||
err = temporalio.exceptions.FailureError(failure.message or "Failure error") | ||
err._failure = failure | ||
|
Uh oh!
There was an error while loading. Please reload this page.