hatchet-sdk 1.18.1__py3-none-any.whl → 1.19.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hatchet-sdk might be problematic. Click here for more details.
- {hatchet_sdk-1.18.1.dist-info → hatchet_sdk-1.19.0.dist-info}/METADATA +2 -3
- {hatchet_sdk-1.18.1.dist-info → hatchet_sdk-1.19.0.dist-info}/RECORD +4 -225
- hatchet_sdk/v0/__init__.py +0 -251
- hatchet_sdk/v0/client.py +0 -119
- hatchet_sdk/v0/clients/admin.py +0 -541
- hatchet_sdk/v0/clients/dispatcher/action_listener.py +0 -422
- hatchet_sdk/v0/clients/dispatcher/dispatcher.py +0 -204
- hatchet_sdk/v0/clients/event_ts.py +0 -28
- hatchet_sdk/v0/clients/events.py +0 -182
- hatchet_sdk/v0/clients/rest/__init__.py +0 -307
- hatchet_sdk/v0/clients/rest/api/__init__.py +0 -19
- hatchet_sdk/v0/clients/rest/api/api_token_api.py +0 -858
- hatchet_sdk/v0/clients/rest/api/default_api.py +0 -2259
- hatchet_sdk/v0/clients/rest/api/event_api.py +0 -2548
- hatchet_sdk/v0/clients/rest/api/github_api.py +0 -331
- hatchet_sdk/v0/clients/rest/api/healthcheck_api.py +0 -483
- hatchet_sdk/v0/clients/rest/api/log_api.py +0 -449
- hatchet_sdk/v0/clients/rest/api/metadata_api.py +0 -728
- hatchet_sdk/v0/clients/rest/api/rate_limits_api.py +0 -423
- hatchet_sdk/v0/clients/rest/api/slack_api.py +0 -577
- hatchet_sdk/v0/clients/rest/api/sns_api.py +0 -872
- hatchet_sdk/v0/clients/rest/api/step_run_api.py +0 -2202
- hatchet_sdk/v0/clients/rest/api/tenant_api.py +0 -4430
- hatchet_sdk/v0/clients/rest/api/user_api.py +0 -2888
- hatchet_sdk/v0/clients/rest/api/worker_api.py +0 -858
- hatchet_sdk/v0/clients/rest/api/workflow_api.py +0 -6312
- hatchet_sdk/v0/clients/rest/api/workflow_run_api.py +0 -1932
- hatchet_sdk/v0/clients/rest/api/workflow_runs_api.py +0 -610
- hatchet_sdk/v0/clients/rest/api_client.py +0 -759
- hatchet_sdk/v0/clients/rest/api_response.py +0 -22
- hatchet_sdk/v0/clients/rest/configuration.py +0 -611
- hatchet_sdk/v0/clients/rest/exceptions.py +0 -200
- hatchet_sdk/v0/clients/rest/models/__init__.py +0 -274
- hatchet_sdk/v0/clients/rest/models/accept_invite_request.py +0 -83
- hatchet_sdk/v0/clients/rest/models/api_error.py +0 -102
- hatchet_sdk/v0/clients/rest/models/api_errors.py +0 -100
- hatchet_sdk/v0/clients/rest/models/api_meta.py +0 -144
- hatchet_sdk/v0/clients/rest/models/api_meta_auth.py +0 -85
- hatchet_sdk/v0/clients/rest/models/api_meta_integration.py +0 -88
- hatchet_sdk/v0/clients/rest/models/api_meta_posthog.py +0 -90
- hatchet_sdk/v0/clients/rest/models/api_resource_meta.py +0 -98
- hatchet_sdk/v0/clients/rest/models/api_token.py +0 -105
- hatchet_sdk/v0/clients/rest/models/bulk_create_event_request.py +0 -100
- hatchet_sdk/v0/clients/rest/models/bulk_create_event_response.py +0 -110
- hatchet_sdk/v0/clients/rest/models/cancel_event_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/cancel_step_run_request.py +0 -83
- hatchet_sdk/v0/clients/rest/models/concurrency_limit_strategy.py +0 -39
- hatchet_sdk/v0/clients/rest/models/create_api_token_request.py +0 -92
- hatchet_sdk/v0/clients/rest/models/create_api_token_response.py +0 -83
- hatchet_sdk/v0/clients/rest/models/create_cron_workflow_trigger_request.py +0 -98
- hatchet_sdk/v0/clients/rest/models/create_event_request.py +0 -95
- hatchet_sdk/v0/clients/rest/models/create_pull_request_from_step_run.py +0 -83
- hatchet_sdk/v0/clients/rest/models/create_sns_integration_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/create_tenant_alert_email_group_request.py +0 -83
- hatchet_sdk/v0/clients/rest/models/create_tenant_invite_request.py +0 -86
- hatchet_sdk/v0/clients/rest/models/create_tenant_request.py +0 -84
- hatchet_sdk/v0/clients/rest/models/cron_workflows.py +0 -131
- hatchet_sdk/v0/clients/rest/models/cron_workflows_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/cron_workflows_method.py +0 -37
- hatchet_sdk/v0/clients/rest/models/cron_workflows_order_by_field.py +0 -37
- hatchet_sdk/v0/clients/rest/models/event.py +0 -143
- hatchet_sdk/v0/clients/rest/models/event_data.py +0 -83
- hatchet_sdk/v0/clients/rest/models/event_key_list.py +0 -98
- hatchet_sdk/v0/clients/rest/models/event_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/event_order_by_direction.py +0 -37
- hatchet_sdk/v0/clients/rest/models/event_order_by_field.py +0 -36
- hatchet_sdk/v0/clients/rest/models/event_update_cancel200_response.py +0 -85
- hatchet_sdk/v0/clients/rest/models/event_workflow_run_summary.py +0 -116
- hatchet_sdk/v0/clients/rest/models/events.py +0 -110
- hatchet_sdk/v0/clients/rest/models/get_step_run_diff_response.py +0 -100
- hatchet_sdk/v0/clients/rest/models/github_app_installation.py +0 -107
- hatchet_sdk/v0/clients/rest/models/github_branch.py +0 -86
- hatchet_sdk/v0/clients/rest/models/github_repo.py +0 -86
- hatchet_sdk/v0/clients/rest/models/info_get_version200_response.py +0 -83
- hatchet_sdk/v0/clients/rest/models/job.py +0 -132
- hatchet_sdk/v0/clients/rest/models/job_run.py +0 -176
- hatchet_sdk/v0/clients/rest/models/job_run_status.py +0 -41
- hatchet_sdk/v0/clients/rest/models/link_github_repository_request.py +0 -106
- hatchet_sdk/v0/clients/rest/models/list_api_tokens_response.py +0 -110
- hatchet_sdk/v0/clients/rest/models/list_github_app_installations_response.py +0 -112
- hatchet_sdk/v0/clients/rest/models/list_pull_requests_response.py +0 -100
- hatchet_sdk/v0/clients/rest/models/list_slack_webhooks.py +0 -110
- hatchet_sdk/v0/clients/rest/models/list_sns_integrations.py +0 -110
- hatchet_sdk/v0/clients/rest/models/log_line.py +0 -94
- hatchet_sdk/v0/clients/rest/models/log_line_level.py +0 -39
- hatchet_sdk/v0/clients/rest/models/log_line_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/log_line_order_by_direction.py +0 -37
- hatchet_sdk/v0/clients/rest/models/log_line_order_by_field.py +0 -36
- hatchet_sdk/v0/clients/rest/models/pagination_response.py +0 -95
- hatchet_sdk/v0/clients/rest/models/pull_request.py +0 -112
- hatchet_sdk/v0/clients/rest/models/pull_request_state.py +0 -37
- hatchet_sdk/v0/clients/rest/models/queue_metrics.py +0 -97
- hatchet_sdk/v0/clients/rest/models/rate_limit.py +0 -117
- hatchet_sdk/v0/clients/rest/models/rate_limit_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/rate_limit_order_by_direction.py +0 -37
- hatchet_sdk/v0/clients/rest/models/rate_limit_order_by_field.py +0 -38
- hatchet_sdk/v0/clients/rest/models/recent_step_runs.py +0 -118
- hatchet_sdk/v0/clients/rest/models/reject_invite_request.py +0 -83
- hatchet_sdk/v0/clients/rest/models/replay_event_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/replay_workflow_runs_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/replay_workflow_runs_response.py +0 -100
- hatchet_sdk/v0/clients/rest/models/rerun_step_run_request.py +0 -83
- hatchet_sdk/v0/clients/rest/models/schedule_workflow_run_request.py +0 -92
- hatchet_sdk/v0/clients/rest/models/scheduled_run_status.py +0 -42
- hatchet_sdk/v0/clients/rest/models/scheduled_workflows.py +0 -149
- hatchet_sdk/v0/clients/rest/models/scheduled_workflows_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/scheduled_workflows_method.py +0 -37
- hatchet_sdk/v0/clients/rest/models/scheduled_workflows_order_by_field.py +0 -37
- hatchet_sdk/v0/clients/rest/models/semaphore_slots.py +0 -113
- hatchet_sdk/v0/clients/rest/models/slack_webhook.py +0 -127
- hatchet_sdk/v0/clients/rest/models/sns_integration.py +0 -114
- hatchet_sdk/v0/clients/rest/models/step.py +0 -123
- hatchet_sdk/v0/clients/rest/models/step_run.py +0 -202
- hatchet_sdk/v0/clients/rest/models/step_run_archive.py +0 -142
- hatchet_sdk/v0/clients/rest/models/step_run_archive_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/step_run_diff.py +0 -91
- hatchet_sdk/v0/clients/rest/models/step_run_event.py +0 -122
- hatchet_sdk/v0/clients/rest/models/step_run_event_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/step_run_event_reason.py +0 -52
- hatchet_sdk/v0/clients/rest/models/step_run_event_severity.py +0 -38
- hatchet_sdk/v0/clients/rest/models/step_run_status.py +0 -44
- hatchet_sdk/v0/clients/rest/models/tenant.py +0 -118
- hatchet_sdk/v0/clients/rest/models/tenant_alert_email_group.py +0 -98
- hatchet_sdk/v0/clients/rest/models/tenant_alert_email_group_list.py +0 -112
- hatchet_sdk/v0/clients/rest/models/tenant_alerting_settings.py +0 -143
- hatchet_sdk/v0/clients/rest/models/tenant_invite.py +0 -120
- hatchet_sdk/v0/clients/rest/models/tenant_invite_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/tenant_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/tenant_member.py +0 -123
- hatchet_sdk/v0/clients/rest/models/tenant_member_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/tenant_member_role.py +0 -38
- hatchet_sdk/v0/clients/rest/models/tenant_queue_metrics.py +0 -116
- hatchet_sdk/v0/clients/rest/models/tenant_resource.py +0 -40
- hatchet_sdk/v0/clients/rest/models/tenant_resource_limit.py +0 -135
- hatchet_sdk/v0/clients/rest/models/tenant_resource_policy.py +0 -102
- hatchet_sdk/v0/clients/rest/models/tenant_step_run_queue_metrics.py +0 -83
- hatchet_sdk/v0/clients/rest/models/trigger_workflow_run_request.py +0 -91
- hatchet_sdk/v0/clients/rest/models/update_tenant_alert_email_group_request.py +0 -83
- hatchet_sdk/v0/clients/rest/models/update_tenant_invite_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/update_tenant_request.py +0 -137
- hatchet_sdk/v0/clients/rest/models/update_worker_request.py +0 -87
- hatchet_sdk/v0/clients/rest/models/user.py +0 -126
- hatchet_sdk/v0/clients/rest/models/user_change_password_request.py +0 -88
- hatchet_sdk/v0/clients/rest/models/user_login_request.py +0 -86
- hatchet_sdk/v0/clients/rest/models/user_register_request.py +0 -91
- hatchet_sdk/v0/clients/rest/models/user_tenant_memberships_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/user_tenant_public.py +0 -86
- hatchet_sdk/v0/clients/rest/models/webhook_worker.py +0 -100
- hatchet_sdk/v0/clients/rest/models/webhook_worker_create_request.py +0 -94
- hatchet_sdk/v0/clients/rest/models/webhook_worker_create_response.py +0 -98
- hatchet_sdk/v0/clients/rest/models/webhook_worker_created.py +0 -102
- hatchet_sdk/v0/clients/rest/models/webhook_worker_list_response.py +0 -110
- hatchet_sdk/v0/clients/rest/models/webhook_worker_request.py +0 -102
- hatchet_sdk/v0/clients/rest/models/webhook_worker_request_list_response.py +0 -104
- hatchet_sdk/v0/clients/rest/models/webhook_worker_request_method.py +0 -38
- hatchet_sdk/v0/clients/rest/models/worker.py +0 -239
- hatchet_sdk/v0/clients/rest/models/worker_label.py +0 -102
- hatchet_sdk/v0/clients/rest/models/worker_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/worker_runtime_info.py +0 -103
- hatchet_sdk/v0/clients/rest/models/worker_runtime_sdks.py +0 -38
- hatchet_sdk/v0/clients/rest/models/worker_type.py +0 -38
- hatchet_sdk/v0/clients/rest/models/workflow.py +0 -165
- hatchet_sdk/v0/clients/rest/models/workflow_concurrency.py +0 -107
- hatchet_sdk/v0/clients/rest/models/workflow_deployment_config.py +0 -136
- hatchet_sdk/v0/clients/rest/models/workflow_kind.py +0 -38
- hatchet_sdk/v0/clients/rest/models/workflow_list.py +0 -120
- hatchet_sdk/v0/clients/rest/models/workflow_metrics.py +0 -97
- hatchet_sdk/v0/clients/rest/models/workflow_run.py +0 -188
- hatchet_sdk/v0/clients/rest/models/workflow_run_cancel200_response.py +0 -85
- hatchet_sdk/v0/clients/rest/models/workflow_run_list.py +0 -110
- hatchet_sdk/v0/clients/rest/models/workflow_run_order_by_direction.py +0 -37
- hatchet_sdk/v0/clients/rest/models/workflow_run_order_by_field.py +0 -39
- hatchet_sdk/v0/clients/rest/models/workflow_run_shape.py +0 -186
- hatchet_sdk/v0/clients/rest/models/workflow_run_status.py +0 -42
- hatchet_sdk/v0/clients/rest/models/workflow_run_triggered_by.py +0 -112
- hatchet_sdk/v0/clients/rest/models/workflow_runs_cancel_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/workflow_runs_metrics.py +0 -94
- hatchet_sdk/v0/clients/rest/models/workflow_runs_metrics_counts.py +0 -104
- hatchet_sdk/v0/clients/rest/models/workflow_tag.py +0 -84
- hatchet_sdk/v0/clients/rest/models/workflow_trigger_cron_ref.py +0 -86
- hatchet_sdk/v0/clients/rest/models/workflow_trigger_event_ref.py +0 -86
- hatchet_sdk/v0/clients/rest/models/workflow_triggers.py +0 -141
- hatchet_sdk/v0/clients/rest/models/workflow_update_request.py +0 -85
- hatchet_sdk/v0/clients/rest/models/workflow_version.py +0 -170
- hatchet_sdk/v0/clients/rest/models/workflow_version_concurrency.py +0 -114
- hatchet_sdk/v0/clients/rest/models/workflow_version_definition.py +0 -85
- hatchet_sdk/v0/clients/rest/models/workflow_version_meta.py +0 -123
- hatchet_sdk/v0/clients/rest/models/workflow_workers_count.py +0 -95
- hatchet_sdk/v0/clients/rest/rest.py +0 -187
- hatchet_sdk/v0/clients/rest/tenacity_utils.py +0 -39
- hatchet_sdk/v0/clients/rest_client.py +0 -622
- hatchet_sdk/v0/clients/run_event_listener.py +0 -260
- hatchet_sdk/v0/clients/workflow_listener.py +0 -277
- hatchet_sdk/v0/connection.py +0 -63
- hatchet_sdk/v0/context/__init__.py +0 -1
- hatchet_sdk/v0/context/context.py +0 -446
- hatchet_sdk/v0/context/worker_context.py +0 -28
- hatchet_sdk/v0/features/cron.py +0 -286
- hatchet_sdk/v0/features/scheduled.py +0 -248
- hatchet_sdk/v0/hatchet.py +0 -310
- hatchet_sdk/v0/labels.py +0 -10
- hatchet_sdk/v0/loader.py +0 -244
- hatchet_sdk/v0/metadata.py +0 -2
- hatchet_sdk/v0/opentelemetry/instrumentor.py +0 -393
- hatchet_sdk/v0/rate_limit.py +0 -126
- hatchet_sdk/v0/semver.py +0 -30
- hatchet_sdk/v0/token.py +0 -27
- hatchet_sdk/v0/utils/aio_utils.py +0 -137
- hatchet_sdk/v0/utils/backoff.py +0 -9
- hatchet_sdk/v0/utils/types.py +0 -8
- hatchet_sdk/v0/utils/typing.py +0 -12
- hatchet_sdk/v0/v2/callable.py +0 -202
- hatchet_sdk/v0/v2/concurrency.py +0 -47
- hatchet_sdk/v0/v2/hatchet.py +0 -224
- hatchet_sdk/v0/worker/__init__.py +0 -1
- hatchet_sdk/v0/worker/action_listener_process.py +0 -294
- hatchet_sdk/v0/worker/runner/run_loop_manager.py +0 -112
- hatchet_sdk/v0/worker/runner/runner.py +0 -460
- hatchet_sdk/v0/worker/runner/utils/capture_logs.py +0 -81
- hatchet_sdk/v0/worker/runner/utils/error_with_traceback.py +0 -6
- hatchet_sdk/v0/worker/worker.py +0 -391
- hatchet_sdk/v0/workflow.py +0 -261
- hatchet_sdk/v0/workflow_run.py +0 -59
- {hatchet_sdk-1.18.1.dist-info → hatchet_sdk-1.19.0.dist-info}/WHEEL +0 -0
- {hatchet_sdk-1.18.1.dist-info → hatchet_sdk-1.19.0.dist-info}/entry_points.txt +0 -0
|
@@ -1,446 +0,0 @@
|
|
|
1
|
-
import inspect
|
|
2
|
-
import json
|
|
3
|
-
import traceback
|
|
4
|
-
from concurrent.futures import Future, ThreadPoolExecutor
|
|
5
|
-
from typing import Any, Generic, Type, TypeVar, cast, overload
|
|
6
|
-
from warnings import warn
|
|
7
|
-
|
|
8
|
-
from pydantic import BaseModel, StrictStr
|
|
9
|
-
|
|
10
|
-
from hatchet_sdk.contracts.dispatcher_pb2 import OverridesData
|
|
11
|
-
from hatchet_sdk.contracts.workflows_pb2 import (
|
|
12
|
-
BulkTriggerWorkflowRequest,
|
|
13
|
-
TriggerWorkflowRequest,
|
|
14
|
-
)
|
|
15
|
-
from hatchet_sdk.v0.clients.events import EventClient
|
|
16
|
-
from hatchet_sdk.v0.clients.rest.tenacity_utils import tenacity_retry
|
|
17
|
-
from hatchet_sdk.v0.clients.rest_client import RestApi
|
|
18
|
-
from hatchet_sdk.v0.clients.run_event_listener import RunEventListenerClient
|
|
19
|
-
from hatchet_sdk.v0.clients.workflow_listener import PooledWorkflowRunListener
|
|
20
|
-
from hatchet_sdk.v0.context.worker_context import WorkerContext
|
|
21
|
-
from hatchet_sdk.v0.utils.types import WorkflowValidator
|
|
22
|
-
from hatchet_sdk.v0.utils.typing import is_basemodel_subclass
|
|
23
|
-
from hatchet_sdk.v0.workflow_run import WorkflowRunRef
|
|
24
|
-
|
|
25
|
-
from ...logger import logger
|
|
26
|
-
from ..clients.admin import (
|
|
27
|
-
AdminClient,
|
|
28
|
-
ChildTriggerWorkflowOptions,
|
|
29
|
-
ChildWorkflowRunDict,
|
|
30
|
-
TriggerWorkflowOptions,
|
|
31
|
-
WorkflowRunDict,
|
|
32
|
-
)
|
|
33
|
-
from ..clients.dispatcher.dispatcher import ( # type: ignore[attr-defined]
|
|
34
|
-
Action,
|
|
35
|
-
DispatcherClient,
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
DEFAULT_WORKFLOW_POLLING_INTERVAL = 5 # Seconds
|
|
39
|
-
|
|
40
|
-
T = TypeVar("T", bound=BaseModel)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
def get_caller_file_path() -> str:
|
|
44
|
-
caller_frame = inspect.stack()[2]
|
|
45
|
-
|
|
46
|
-
return caller_frame.filename
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
class BaseContext:
|
|
50
|
-
|
|
51
|
-
action: Action
|
|
52
|
-
spawn_index: int
|
|
53
|
-
|
|
54
|
-
def _prepare_workflow_options(
|
|
55
|
-
self,
|
|
56
|
-
key: str | None = None,
|
|
57
|
-
options: ChildTriggerWorkflowOptions | None = None,
|
|
58
|
-
worker_id: str | None = None,
|
|
59
|
-
) -> TriggerWorkflowOptions:
|
|
60
|
-
workflow_run_id = self.action.workflow_run_id
|
|
61
|
-
step_run_id = self.action.step_run_id
|
|
62
|
-
|
|
63
|
-
desired_worker_id = None
|
|
64
|
-
if options is not None and "sticky" in options and options["sticky"] == True:
|
|
65
|
-
desired_worker_id = worker_id
|
|
66
|
-
|
|
67
|
-
meta = None
|
|
68
|
-
if options is not None and "additional_metadata" in options:
|
|
69
|
-
meta = options["additional_metadata"]
|
|
70
|
-
|
|
71
|
-
## TODO: Pydantic here to simplify this
|
|
72
|
-
trigger_options: TriggerWorkflowOptions = {
|
|
73
|
-
"parent_id": workflow_run_id,
|
|
74
|
-
"parent_step_run_id": step_run_id,
|
|
75
|
-
"child_key": key,
|
|
76
|
-
"child_index": self.spawn_index,
|
|
77
|
-
"additional_metadata": meta,
|
|
78
|
-
"desired_worker_id": desired_worker_id,
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
self.spawn_index += 1
|
|
82
|
-
return trigger_options
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
class ContextAioImpl(BaseContext):
|
|
86
|
-
def __init__(
|
|
87
|
-
self,
|
|
88
|
-
action: Action,
|
|
89
|
-
dispatcher_client: DispatcherClient,
|
|
90
|
-
admin_client: AdminClient,
|
|
91
|
-
event_client: EventClient,
|
|
92
|
-
rest_client: RestApi,
|
|
93
|
-
workflow_listener: PooledWorkflowRunListener,
|
|
94
|
-
workflow_run_event_listener: RunEventListenerClient,
|
|
95
|
-
worker: WorkerContext,
|
|
96
|
-
namespace: str = "",
|
|
97
|
-
):
|
|
98
|
-
self.action = action
|
|
99
|
-
self.dispatcher_client = dispatcher_client
|
|
100
|
-
self.admin_client = admin_client
|
|
101
|
-
self.event_client = event_client
|
|
102
|
-
self.rest_client = rest_client
|
|
103
|
-
self.workflow_listener = workflow_listener
|
|
104
|
-
self.workflow_run_event_listener = workflow_run_event_listener
|
|
105
|
-
self.namespace = namespace
|
|
106
|
-
self.spawn_index = -1
|
|
107
|
-
self.worker = worker
|
|
108
|
-
|
|
109
|
-
@tenacity_retry
|
|
110
|
-
async def spawn_workflow(
|
|
111
|
-
self,
|
|
112
|
-
workflow_name: str,
|
|
113
|
-
input: dict[str, Any] = {},
|
|
114
|
-
key: str | None = None,
|
|
115
|
-
options: ChildTriggerWorkflowOptions | None = None,
|
|
116
|
-
) -> WorkflowRunRef:
|
|
117
|
-
worker_id = self.worker.id()
|
|
118
|
-
# if (
|
|
119
|
-
# options is not None
|
|
120
|
-
# and "sticky" in options
|
|
121
|
-
# and options["sticky"] == True
|
|
122
|
-
# and not self.worker.has_workflow(workflow_name)
|
|
123
|
-
# ):
|
|
124
|
-
# raise Exception(
|
|
125
|
-
# f"cannot run with sticky: workflow {workflow_name} is not registered on the worker"
|
|
126
|
-
# )
|
|
127
|
-
|
|
128
|
-
trigger_options = self._prepare_workflow_options(key, options, worker_id)
|
|
129
|
-
|
|
130
|
-
return await self.admin_client.aio.run_workflow(
|
|
131
|
-
workflow_name, input, trigger_options
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
@tenacity_retry
|
|
135
|
-
async def spawn_workflows(
|
|
136
|
-
self, child_workflow_runs: list[ChildWorkflowRunDict]
|
|
137
|
-
) -> list[WorkflowRunRef]:
|
|
138
|
-
|
|
139
|
-
if len(child_workflow_runs) == 0:
|
|
140
|
-
raise Exception("no child workflows to spawn")
|
|
141
|
-
|
|
142
|
-
worker_id = self.worker.id()
|
|
143
|
-
|
|
144
|
-
bulk_trigger_workflow_runs: list[WorkflowRunDict] = []
|
|
145
|
-
for child_workflow_run in child_workflow_runs:
|
|
146
|
-
workflow_name = child_workflow_run["workflow_name"]
|
|
147
|
-
input = child_workflow_run["input"]
|
|
148
|
-
|
|
149
|
-
key = child_workflow_run.get("key")
|
|
150
|
-
options = child_workflow_run.get("options", {})
|
|
151
|
-
|
|
152
|
-
trigger_options = self._prepare_workflow_options(key, options, worker_id)
|
|
153
|
-
|
|
154
|
-
bulk_trigger_workflow_runs.append(
|
|
155
|
-
WorkflowRunDict(
|
|
156
|
-
workflow_name=workflow_name, input=input, options=trigger_options
|
|
157
|
-
)
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
return await self.admin_client.aio.run_workflows(bulk_trigger_workflow_runs)
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
class Context(BaseContext):
|
|
164
|
-
spawn_index = -1
|
|
165
|
-
|
|
166
|
-
worker: WorkerContext
|
|
167
|
-
|
|
168
|
-
def __init__(
|
|
169
|
-
self,
|
|
170
|
-
action: Action,
|
|
171
|
-
dispatcher_client: DispatcherClient,
|
|
172
|
-
admin_client: AdminClient,
|
|
173
|
-
event_client: EventClient,
|
|
174
|
-
rest_client: RestApi,
|
|
175
|
-
workflow_listener: PooledWorkflowRunListener,
|
|
176
|
-
workflow_run_event_listener: RunEventListenerClient,
|
|
177
|
-
worker: WorkerContext,
|
|
178
|
-
namespace: str = "",
|
|
179
|
-
validator_registry: dict[str, WorkflowValidator] = {},
|
|
180
|
-
):
|
|
181
|
-
self.worker = worker
|
|
182
|
-
self.validator_registry = validator_registry
|
|
183
|
-
|
|
184
|
-
self.aio = ContextAioImpl(
|
|
185
|
-
action,
|
|
186
|
-
dispatcher_client,
|
|
187
|
-
admin_client,
|
|
188
|
-
event_client,
|
|
189
|
-
rest_client,
|
|
190
|
-
workflow_listener,
|
|
191
|
-
workflow_run_event_listener,
|
|
192
|
-
worker,
|
|
193
|
-
namespace,
|
|
194
|
-
)
|
|
195
|
-
|
|
196
|
-
# Check the type of action.action_payload before attempting to load it as JSON
|
|
197
|
-
if isinstance(action.action_payload, (str, bytes, bytearray)):
|
|
198
|
-
try:
|
|
199
|
-
self.data = cast(dict[str, Any], json.loads(action.action_payload))
|
|
200
|
-
except Exception as e:
|
|
201
|
-
logger.error(f"Error parsing action payload: {e}")
|
|
202
|
-
# Assign an empty dictionary if parsing fails
|
|
203
|
-
self.data: dict[str, Any] = {} # type: ignore[no-redef]
|
|
204
|
-
else:
|
|
205
|
-
# Directly assign the payload to self.data if it's already a dict
|
|
206
|
-
self.data = (
|
|
207
|
-
action.action_payload if isinstance(action.action_payload, dict) else {}
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
self.action = action
|
|
211
|
-
|
|
212
|
-
# FIXME: stepRunId is a legacy field, we should remove it
|
|
213
|
-
self.stepRunId = action.step_run_id
|
|
214
|
-
|
|
215
|
-
self.step_run_id = action.step_run_id
|
|
216
|
-
self.exit_flag = False
|
|
217
|
-
self.dispatcher_client = dispatcher_client
|
|
218
|
-
self.admin_client = admin_client
|
|
219
|
-
self.event_client = event_client
|
|
220
|
-
self.rest_client = rest_client
|
|
221
|
-
self.workflow_listener = workflow_listener
|
|
222
|
-
self.workflow_run_event_listener = workflow_run_event_listener
|
|
223
|
-
self.namespace = namespace
|
|
224
|
-
|
|
225
|
-
# FIXME: this limits the number of concurrent log requests to 1, which means we can do about
|
|
226
|
-
# 100 log lines per second but this depends on network.
|
|
227
|
-
self.logger_thread_pool = ThreadPoolExecutor(max_workers=1)
|
|
228
|
-
self.stream_event_thread_pool = ThreadPoolExecutor(max_workers=1)
|
|
229
|
-
|
|
230
|
-
# store each key in the overrides field in a lookup table
|
|
231
|
-
# overrides_data is a dictionary of key-value pairs
|
|
232
|
-
self.overrides_data = self.data.get("overrides", {})
|
|
233
|
-
|
|
234
|
-
if action.get_group_key_run_id != "":
|
|
235
|
-
self.input = self.data
|
|
236
|
-
else:
|
|
237
|
-
self.input = self.data.get("input", {})
|
|
238
|
-
|
|
239
|
-
def step_output(self, step: str) -> dict[str, Any] | BaseModel:
|
|
240
|
-
workflow_validator = next(
|
|
241
|
-
(v for k, v in self.validator_registry.items() if k.split(":")[-1] == step),
|
|
242
|
-
None,
|
|
243
|
-
)
|
|
244
|
-
|
|
245
|
-
try:
|
|
246
|
-
parent_step_data = cast(dict[str, Any], self.data["parents"][step])
|
|
247
|
-
except KeyError:
|
|
248
|
-
raise ValueError(f"Step output for '{step}' not found")
|
|
249
|
-
|
|
250
|
-
if workflow_validator and (v := workflow_validator.step_output):
|
|
251
|
-
return v.model_validate(parent_step_data)
|
|
252
|
-
|
|
253
|
-
return parent_step_data
|
|
254
|
-
|
|
255
|
-
def triggered_by_event(self) -> bool:
|
|
256
|
-
return cast(str, self.data.get("triggered_by", "")) == "event"
|
|
257
|
-
|
|
258
|
-
def workflow_input(self) -> dict[str, Any] | T:
|
|
259
|
-
if (r := self.validator_registry.get(self.action.action_id)) and (
|
|
260
|
-
i := r.workflow_input
|
|
261
|
-
):
|
|
262
|
-
return cast(
|
|
263
|
-
T,
|
|
264
|
-
i.model_validate(self.input),
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
return self.input
|
|
268
|
-
|
|
269
|
-
def workflow_run_id(self) -> str:
|
|
270
|
-
return self.action.workflow_run_id
|
|
271
|
-
|
|
272
|
-
def cancel(self) -> None:
|
|
273
|
-
logger.debug("cancelling step...")
|
|
274
|
-
self.exit_flag = True
|
|
275
|
-
|
|
276
|
-
# done returns true if the context has been cancelled
|
|
277
|
-
def done(self) -> bool:
|
|
278
|
-
return self.exit_flag
|
|
279
|
-
|
|
280
|
-
def playground(self, name: str, default: str | None = None) -> str | None:
|
|
281
|
-
# if the key exists in the overrides_data field, return the value
|
|
282
|
-
if name in self.overrides_data:
|
|
283
|
-
warn(
|
|
284
|
-
"Use of `overrides_data` is deprecated.",
|
|
285
|
-
DeprecationWarning,
|
|
286
|
-
stacklevel=1,
|
|
287
|
-
)
|
|
288
|
-
return str(self.overrides_data[name])
|
|
289
|
-
|
|
290
|
-
caller_file = get_caller_file_path()
|
|
291
|
-
|
|
292
|
-
self.dispatcher_client.put_overrides_data(
|
|
293
|
-
OverridesData(
|
|
294
|
-
stepRunId=self.stepRunId,
|
|
295
|
-
path=name,
|
|
296
|
-
value=json.dumps(default),
|
|
297
|
-
callerFilename=caller_file,
|
|
298
|
-
)
|
|
299
|
-
)
|
|
300
|
-
|
|
301
|
-
return default
|
|
302
|
-
|
|
303
|
-
def _log(self, line: str) -> tuple[bool, Exception | None]:
|
|
304
|
-
try:
|
|
305
|
-
self.event_client.log(message=line, step_run_id=self.stepRunId)
|
|
306
|
-
return True, None
|
|
307
|
-
except Exception as e:
|
|
308
|
-
# we don't want to raise an exception here, as it will kill the log thread
|
|
309
|
-
return False, e
|
|
310
|
-
|
|
311
|
-
def log(self, line: Any, raise_on_error: bool = False) -> None:
|
|
312
|
-
if self.stepRunId == "":
|
|
313
|
-
return
|
|
314
|
-
|
|
315
|
-
if not isinstance(line, str):
|
|
316
|
-
try:
|
|
317
|
-
line = json.dumps(line)
|
|
318
|
-
except Exception:
|
|
319
|
-
line = str(line)
|
|
320
|
-
|
|
321
|
-
future = self.logger_thread_pool.submit(self._log, line)
|
|
322
|
-
|
|
323
|
-
def handle_result(future: Future[tuple[bool, Exception | None]]) -> None:
|
|
324
|
-
success, exception = future.result()
|
|
325
|
-
if not success and exception:
|
|
326
|
-
if raise_on_error:
|
|
327
|
-
raise exception
|
|
328
|
-
else:
|
|
329
|
-
thread_trace = "".join(
|
|
330
|
-
traceback.format_exception(
|
|
331
|
-
type(exception), exception, exception.__traceback__
|
|
332
|
-
)
|
|
333
|
-
)
|
|
334
|
-
call_site_trace = "".join(traceback.format_stack())
|
|
335
|
-
logger.error(
|
|
336
|
-
f"Error in log thread: {exception}\n{thread_trace}\nCalled from:\n{call_site_trace}"
|
|
337
|
-
)
|
|
338
|
-
|
|
339
|
-
future.add_done_callback(handle_result)
|
|
340
|
-
|
|
341
|
-
def release_slot(self) -> None:
|
|
342
|
-
return self.dispatcher_client.release_slot(self.stepRunId)
|
|
343
|
-
|
|
344
|
-
def _put_stream(self, data: str | bytes) -> None:
|
|
345
|
-
try:
|
|
346
|
-
self.event_client.stream(data=data, step_run_id=self.stepRunId)
|
|
347
|
-
except Exception as e:
|
|
348
|
-
logger.error(f"Error putting stream event: {e}")
|
|
349
|
-
|
|
350
|
-
def put_stream(self, data: str | bytes) -> None:
|
|
351
|
-
if self.stepRunId == "":
|
|
352
|
-
return
|
|
353
|
-
|
|
354
|
-
self.stream_event_thread_pool.submit(self._put_stream, data)
|
|
355
|
-
|
|
356
|
-
def refresh_timeout(self, increment_by: str) -> None:
|
|
357
|
-
try:
|
|
358
|
-
return self.dispatcher_client.refresh_timeout(
|
|
359
|
-
step_run_id=self.stepRunId, increment_by=increment_by
|
|
360
|
-
)
|
|
361
|
-
except Exception as e:
|
|
362
|
-
logger.error(f"Error refreshing timeout: {e}")
|
|
363
|
-
|
|
364
|
-
def retry_count(self) -> int:
|
|
365
|
-
return self.action.retry_count
|
|
366
|
-
|
|
367
|
-
def additional_metadata(self) -> dict[str, Any] | None:
|
|
368
|
-
return self.action.additional_metadata
|
|
369
|
-
|
|
370
|
-
def child_index(self) -> int | None:
|
|
371
|
-
return self.action.child_workflow_index
|
|
372
|
-
|
|
373
|
-
def child_key(self) -> str | None:
|
|
374
|
-
return self.action.child_workflow_key
|
|
375
|
-
|
|
376
|
-
def parent_workflow_run_id(self) -> str | None:
|
|
377
|
-
return self.action.parent_workflow_run_id
|
|
378
|
-
|
|
379
|
-
def step_run_errors(self) -> dict[str, str]:
|
|
380
|
-
errors = cast(dict[str, str], self.data.get("step_run_errors", {}))
|
|
381
|
-
|
|
382
|
-
if not errors:
|
|
383
|
-
logger.error(
|
|
384
|
-
"No step run errors found. `context.step_run_errors` is intended to be run in an on-failure step, and will only work on engine versions more recent than v0.53.10"
|
|
385
|
-
)
|
|
386
|
-
|
|
387
|
-
return errors
|
|
388
|
-
|
|
389
|
-
def fetch_run_failures(self) -> list[dict[str, StrictStr]]:
|
|
390
|
-
data = self.rest_client.workflow_run_get(self.action.workflow_run_id)
|
|
391
|
-
other_job_runs = [
|
|
392
|
-
run for run in (data.job_runs or []) if run.job_id != self.action.job_id
|
|
393
|
-
]
|
|
394
|
-
# TODO: Parse Step Runs using a Pydantic Model rather than a hand crafted dictionary
|
|
395
|
-
return [
|
|
396
|
-
{
|
|
397
|
-
"step_id": step_run.step_id,
|
|
398
|
-
"step_run_action_name": step_run.step.action,
|
|
399
|
-
"error": step_run.error,
|
|
400
|
-
}
|
|
401
|
-
for job_run in other_job_runs
|
|
402
|
-
if job_run.step_runs
|
|
403
|
-
for step_run in job_run.step_runs
|
|
404
|
-
if step_run.error and step_run.step
|
|
405
|
-
]
|
|
406
|
-
|
|
407
|
-
@tenacity_retry
|
|
408
|
-
def spawn_workflow(
|
|
409
|
-
self,
|
|
410
|
-
workflow_name: str,
|
|
411
|
-
input: dict[str, Any] = {},
|
|
412
|
-
key: str | None = None,
|
|
413
|
-
options: ChildTriggerWorkflowOptions | None = None,
|
|
414
|
-
) -> WorkflowRunRef:
|
|
415
|
-
worker_id = self.worker.id()
|
|
416
|
-
trigger_options = self._prepare_workflow_options(key, options, worker_id)
|
|
417
|
-
|
|
418
|
-
return self.admin_client.run_workflow(workflow_name, input, trigger_options)
|
|
419
|
-
|
|
420
|
-
@tenacity_retry
|
|
421
|
-
def spawn_workflows(
|
|
422
|
-
self, child_workflow_runs: list[ChildWorkflowRunDict]
|
|
423
|
-
) -> list[WorkflowRunRef]:
|
|
424
|
-
|
|
425
|
-
if len(child_workflow_runs) == 0:
|
|
426
|
-
raise Exception("no child workflows to spawn")
|
|
427
|
-
|
|
428
|
-
worker_id = self.worker.id()
|
|
429
|
-
|
|
430
|
-
bulk_trigger_workflow_runs: list[WorkflowRunDict] = []
|
|
431
|
-
for child_workflow_run in child_workflow_runs:
|
|
432
|
-
workflow_name = child_workflow_run["workflow_name"]
|
|
433
|
-
input = child_workflow_run["input"]
|
|
434
|
-
|
|
435
|
-
key = child_workflow_run.get("key")
|
|
436
|
-
options = child_workflow_run.get("options", {})
|
|
437
|
-
|
|
438
|
-
trigger_options = self._prepare_workflow_options(key, options, worker_id)
|
|
439
|
-
|
|
440
|
-
bulk_trigger_workflow_runs.append(
|
|
441
|
-
WorkflowRunDict(
|
|
442
|
-
workflow_name=workflow_name, input=input, options=trigger_options
|
|
443
|
-
)
|
|
444
|
-
)
|
|
445
|
-
|
|
446
|
-
return self.admin_client.run_workflows(bulk_trigger_workflow_runs)
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
from hatchet_sdk.v0.clients.dispatcher.dispatcher import DispatcherClient
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class WorkerContext:
|
|
5
|
-
_worker_id: str | None = None
|
|
6
|
-
_registered_workflow_names: list[str] = []
|
|
7
|
-
_labels: dict[str, str | int] = {}
|
|
8
|
-
|
|
9
|
-
def __init__(self, labels: dict[str, str | int], client: DispatcherClient):
|
|
10
|
-
self._labels = labels
|
|
11
|
-
self.client = client
|
|
12
|
-
|
|
13
|
-
def labels(self) -> dict[str, str | int]:
|
|
14
|
-
return self._labels
|
|
15
|
-
|
|
16
|
-
def upsert_labels(self, labels: dict[str, str | int]) -> None:
|
|
17
|
-
self.client.upsert_worker_labels(self._worker_id, labels)
|
|
18
|
-
self._labels.update(labels)
|
|
19
|
-
|
|
20
|
-
async def async_upsert_labels(self, labels: dict[str, str | int]) -> None:
|
|
21
|
-
await self.client.async_upsert_worker_labels(self._worker_id, labels)
|
|
22
|
-
self._labels.update(labels)
|
|
23
|
-
|
|
24
|
-
def id(self) -> str | None:
|
|
25
|
-
return self._worker_id
|
|
26
|
-
|
|
27
|
-
# def has_workflow(self, workflow_name: str):
|
|
28
|
-
# return workflow_name in self._registered_workflow_names
|