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,137 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import inspect
|
|
3
|
-
from concurrent.futures import Executor
|
|
4
|
-
from functools import partial, wraps
|
|
5
|
-
from threading import Thread
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
## TODO: Stricter typing here
|
|
10
|
-
def sync_to_async(func: Any) -> Any:
|
|
11
|
-
"""
|
|
12
|
-
A decorator to run a synchronous function or coroutine in an asynchronous context with added
|
|
13
|
-
asyncio loop safety.
|
|
14
|
-
|
|
15
|
-
This decorator allows you to safely call synchronous functions or coroutines from an
|
|
16
|
-
asynchronous function by running them in an executor.
|
|
17
|
-
|
|
18
|
-
Args:
|
|
19
|
-
func (callable): The synchronous function or coroutine to be run asynchronously.
|
|
20
|
-
|
|
21
|
-
Returns:
|
|
22
|
-
callable: An asynchronous wrapper function that runs the given function in an executor.
|
|
23
|
-
|
|
24
|
-
Example:
|
|
25
|
-
@sync_to_async
|
|
26
|
-
def sync_function(x, y):
|
|
27
|
-
return x + y
|
|
28
|
-
|
|
29
|
-
@sync_to_async
|
|
30
|
-
async def async_function(x, y):
|
|
31
|
-
return x + y
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
def undecorated_function(x, y):
|
|
35
|
-
return x + y
|
|
36
|
-
|
|
37
|
-
async def main():
|
|
38
|
-
result1 = await sync_function(1, 2)
|
|
39
|
-
result2 = await async_function(3, 4)
|
|
40
|
-
result3 = await sync_to_async(undecorated_function)(5, 6)
|
|
41
|
-
print(result1, result2, result3)
|
|
42
|
-
|
|
43
|
-
asyncio.run(main())
|
|
44
|
-
"""
|
|
45
|
-
|
|
46
|
-
## TODO: Stricter typing here
|
|
47
|
-
@wraps(func)
|
|
48
|
-
async def run(
|
|
49
|
-
*args: Any,
|
|
50
|
-
loop: asyncio.AbstractEventLoop | None = None,
|
|
51
|
-
executor: Executor | None = None,
|
|
52
|
-
**kwargs: Any
|
|
53
|
-
) -> Any:
|
|
54
|
-
"""
|
|
55
|
-
The asynchronous wrapper function that runs the given function in an executor.
|
|
56
|
-
|
|
57
|
-
Args:
|
|
58
|
-
*args: Positional arguments to pass to the function.
|
|
59
|
-
loop (asyncio.AbstractEventLoop, optional): The event loop to use. If None, the current running loop is used.
|
|
60
|
-
executor (concurrent.futures.Executor, optional): The executor to use. If None, the default executor is used.
|
|
61
|
-
**kwargs: Keyword arguments to pass to the function.
|
|
62
|
-
|
|
63
|
-
Returns:
|
|
64
|
-
The result of the function call.
|
|
65
|
-
"""
|
|
66
|
-
if loop is None:
|
|
67
|
-
loop = asyncio.get_running_loop()
|
|
68
|
-
|
|
69
|
-
if inspect.iscoroutinefunction(func):
|
|
70
|
-
# Wrap the coroutine to run it in an executor
|
|
71
|
-
async def wrapper() -> Any:
|
|
72
|
-
return await func(*args, **kwargs)
|
|
73
|
-
|
|
74
|
-
pfunc = partial(asyncio.run, wrapper())
|
|
75
|
-
return await loop.run_in_executor(executor, pfunc)
|
|
76
|
-
else:
|
|
77
|
-
# Run the synchronous function in an executor
|
|
78
|
-
pfunc = partial(func, *args, **kwargs)
|
|
79
|
-
return await loop.run_in_executor(executor, pfunc)
|
|
80
|
-
|
|
81
|
-
return run
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
class EventLoopThread:
|
|
85
|
-
"""A class that manages an asyncio event loop running in a separate thread."""
|
|
86
|
-
|
|
87
|
-
def __init__(self) -> None:
|
|
88
|
-
"""
|
|
89
|
-
Initializes the EventLoopThread by creating an event loop
|
|
90
|
-
and setting up a thread to run the loop.
|
|
91
|
-
"""
|
|
92
|
-
self.loop = asyncio.new_event_loop()
|
|
93
|
-
self.thread = Thread(target=self.run_loop_in_thread, args=(self.loop,))
|
|
94
|
-
|
|
95
|
-
def __enter__(self, *a, **kw) -> asyncio.AbstractEventLoop:
|
|
96
|
-
"""
|
|
97
|
-
Starts the thread running the event loop when entering the context.
|
|
98
|
-
|
|
99
|
-
Returns:
|
|
100
|
-
asyncio.AbstractEventLoop: The event loop running in the separate thread.
|
|
101
|
-
"""
|
|
102
|
-
self.thread.start()
|
|
103
|
-
return self.loop
|
|
104
|
-
|
|
105
|
-
def __exit__(self, *a, **kw) -> None:
|
|
106
|
-
"""
|
|
107
|
-
Stops the event loop and joins the thread when exiting the context.
|
|
108
|
-
"""
|
|
109
|
-
self.loop.call_soon_threadsafe(self.loop.stop)
|
|
110
|
-
self.thread.join()
|
|
111
|
-
|
|
112
|
-
def run_loop_in_thread(self, loop: asyncio.AbstractEventLoop) -> None:
|
|
113
|
-
"""
|
|
114
|
-
Sets the event loop for the current thread and runs it forever.
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
loop (asyncio.AbstractEventLoop): The event loop to run.
|
|
118
|
-
"""
|
|
119
|
-
asyncio.set_event_loop(loop)
|
|
120
|
-
loop.run_forever()
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def get_active_event_loop() -> asyncio.AbstractEventLoop | None:
|
|
124
|
-
"""
|
|
125
|
-
Get the active event loop.
|
|
126
|
-
|
|
127
|
-
Returns:
|
|
128
|
-
asyncio.AbstractEventLoop: The active event loop, or None if there is no active
|
|
129
|
-
event loop in the current thread.
|
|
130
|
-
"""
|
|
131
|
-
try:
|
|
132
|
-
return asyncio.get_event_loop()
|
|
133
|
-
except RuntimeError as e:
|
|
134
|
-
if str(e).startswith("There is no current event loop in thread"):
|
|
135
|
-
return None
|
|
136
|
-
else:
|
|
137
|
-
raise e
|
hatchet_sdk/v0/utils/backoff.py
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
import random
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
async def exp_backoff_sleep(attempt: int, max_sleep_time: float = 5) -> None:
|
|
6
|
-
base_time = 0.1 # starting sleep time in seconds (100 milliseconds)
|
|
7
|
-
jitter = random.uniform(0, base_time) # add random jitter
|
|
8
|
-
sleep_time = min(base_time * (2**attempt) + jitter, max_sleep_time)
|
|
9
|
-
await asyncio.sleep(sleep_time)
|
hatchet_sdk/v0/utils/types.py
DELETED
hatchet_sdk/v0/utils/typing.py
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
from typing import Any, Type, TypeGuard, TypeVar
|
|
2
|
-
|
|
3
|
-
from pydantic import BaseModel
|
|
4
|
-
|
|
5
|
-
T = TypeVar("T", bound=BaseModel)
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def is_basemodel_subclass(model: Any) -> bool:
|
|
9
|
-
try:
|
|
10
|
-
return issubclass(model, BaseModel)
|
|
11
|
-
except TypeError:
|
|
12
|
-
return False
|
hatchet_sdk/v0/v2/callable.py
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import asyncio
|
|
2
|
-
from typing import (
|
|
3
|
-
Any,
|
|
4
|
-
Callable,
|
|
5
|
-
Dict,
|
|
6
|
-
Generic,
|
|
7
|
-
List,
|
|
8
|
-
Optional,
|
|
9
|
-
TypedDict,
|
|
10
|
-
TypeVar,
|
|
11
|
-
Union,
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
from hatchet_sdk.contracts.workflows_pb2 import ( # type: ignore[attr-defined]
|
|
15
|
-
CreateStepRateLimit,
|
|
16
|
-
CreateWorkflowJobOpts,
|
|
17
|
-
CreateWorkflowStepOpts,
|
|
18
|
-
CreateWorkflowVersionOpts,
|
|
19
|
-
DesiredWorkerLabels,
|
|
20
|
-
StickyStrategy,
|
|
21
|
-
WorkflowConcurrencyOpts,
|
|
22
|
-
WorkflowKind,
|
|
23
|
-
)
|
|
24
|
-
from hatchet_sdk.logger import logger
|
|
25
|
-
from hatchet_sdk.v0.clients.admin import ChildTriggerWorkflowOptions
|
|
26
|
-
from hatchet_sdk.v0.context.context import Context
|
|
27
|
-
from hatchet_sdk.v0.labels import DesiredWorkerLabel
|
|
28
|
-
from hatchet_sdk.v0.rate_limit import RateLimit
|
|
29
|
-
from hatchet_sdk.v0.v2.concurrency import ConcurrencyFunction
|
|
30
|
-
from hatchet_sdk.v0.workflow_run import RunRef
|
|
31
|
-
|
|
32
|
-
T = TypeVar("T")
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class HatchetCallable(Generic[T]):
|
|
36
|
-
def __init__(
|
|
37
|
-
self,
|
|
38
|
-
func: Callable[[Context], T],
|
|
39
|
-
durable: bool = False,
|
|
40
|
-
name: str = "",
|
|
41
|
-
auto_register: bool = True,
|
|
42
|
-
on_events: list[str] | None = None,
|
|
43
|
-
on_crons: list[str] | None = None,
|
|
44
|
-
version: str = "",
|
|
45
|
-
timeout: str = "60m",
|
|
46
|
-
schedule_timeout: str = "5m",
|
|
47
|
-
sticky: StickyStrategy = None,
|
|
48
|
-
retries: int = 0,
|
|
49
|
-
rate_limits: List[RateLimit] | None = None,
|
|
50
|
-
concurrency: ConcurrencyFunction | None = None,
|
|
51
|
-
on_failure: Union["HatchetCallable[T]", None] = None,
|
|
52
|
-
desired_worker_labels: dict[str, DesiredWorkerLabel] = {},
|
|
53
|
-
default_priority: int | None = None,
|
|
54
|
-
):
|
|
55
|
-
self.func = func
|
|
56
|
-
|
|
57
|
-
on_events = on_events or []
|
|
58
|
-
on_crons = on_crons or []
|
|
59
|
-
|
|
60
|
-
limits = None
|
|
61
|
-
if rate_limits:
|
|
62
|
-
limits = [rate_limit._req for rate_limit in rate_limits or []]
|
|
63
|
-
|
|
64
|
-
self.function_desired_worker_labels = {}
|
|
65
|
-
|
|
66
|
-
for key, d in desired_worker_labels.items():
|
|
67
|
-
value = d["value"] if "value" in d else None
|
|
68
|
-
self.function_desired_worker_labels[key] = DesiredWorkerLabels(
|
|
69
|
-
strValue=str(value) if not isinstance(value, int) else None,
|
|
70
|
-
intValue=value if isinstance(value, int) else None,
|
|
71
|
-
required=d["required"] if "required" in d else None,
|
|
72
|
-
weight=d["weight"] if "weight" in d else None,
|
|
73
|
-
comparator=d["comparator"] if "comparator" in d else None,
|
|
74
|
-
)
|
|
75
|
-
self.sticky = sticky
|
|
76
|
-
self.default_priority = default_priority
|
|
77
|
-
self.durable = durable
|
|
78
|
-
self.function_name = name.lower() or str(func.__name__).lower()
|
|
79
|
-
self.function_version = version
|
|
80
|
-
self.function_on_events = on_events
|
|
81
|
-
self.function_on_crons = on_crons
|
|
82
|
-
self.function_timeout = timeout
|
|
83
|
-
self.function_schedule_timeout = schedule_timeout
|
|
84
|
-
self.function_retries = retries
|
|
85
|
-
self.function_rate_limits = limits
|
|
86
|
-
self.function_concurrency = concurrency
|
|
87
|
-
self.function_on_failure = on_failure
|
|
88
|
-
self.function_namespace = "default"
|
|
89
|
-
self.function_auto_register = auto_register
|
|
90
|
-
|
|
91
|
-
self.is_coroutine = False
|
|
92
|
-
|
|
93
|
-
if asyncio.iscoroutinefunction(func):
|
|
94
|
-
self.is_coroutine = True
|
|
95
|
-
|
|
96
|
-
def __call__(self, context: Context) -> T:
|
|
97
|
-
return self.func(context)
|
|
98
|
-
|
|
99
|
-
def with_namespace(self, namespace: str) -> None:
|
|
100
|
-
if namespace is not None and namespace != "":
|
|
101
|
-
self.function_namespace = namespace
|
|
102
|
-
self.function_name = namespace + self.function_name
|
|
103
|
-
|
|
104
|
-
def to_workflow_opts(self) -> CreateWorkflowVersionOpts:
|
|
105
|
-
kind: WorkflowKind = WorkflowKind.FUNCTION
|
|
106
|
-
|
|
107
|
-
if self.durable:
|
|
108
|
-
kind = WorkflowKind.DURABLE
|
|
109
|
-
|
|
110
|
-
on_failure_job: CreateWorkflowJobOpts | None = None
|
|
111
|
-
|
|
112
|
-
if self.function_on_failure is not None:
|
|
113
|
-
on_failure_job = CreateWorkflowJobOpts(
|
|
114
|
-
name=self.function_name + "-on-failure",
|
|
115
|
-
steps=[
|
|
116
|
-
self.function_on_failure.to_step(),
|
|
117
|
-
],
|
|
118
|
-
)
|
|
119
|
-
|
|
120
|
-
concurrency: WorkflowConcurrencyOpts | None = None
|
|
121
|
-
|
|
122
|
-
if self.function_concurrency is not None:
|
|
123
|
-
self.function_concurrency.set_namespace(self.function_namespace)
|
|
124
|
-
concurrency = WorkflowConcurrencyOpts(
|
|
125
|
-
action=self.function_concurrency.get_action_name(),
|
|
126
|
-
max_runs=self.function_concurrency.max_runs,
|
|
127
|
-
limit_strategy=self.function_concurrency.limit_strategy,
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
validated_priority = (
|
|
131
|
-
max(1, min(3, self.default_priority)) if self.default_priority else None
|
|
132
|
-
)
|
|
133
|
-
if validated_priority != self.default_priority:
|
|
134
|
-
logger.warning(
|
|
135
|
-
"Warning: Default Priority Must be between 1 and 3 -- inclusively. Adjusted to be within the range."
|
|
136
|
-
)
|
|
137
|
-
|
|
138
|
-
return CreateWorkflowVersionOpts(
|
|
139
|
-
name=self.function_name,
|
|
140
|
-
kind=kind,
|
|
141
|
-
version=self.function_version,
|
|
142
|
-
event_triggers=self.function_on_events,
|
|
143
|
-
cron_triggers=self.function_on_crons,
|
|
144
|
-
schedule_timeout=self.function_schedule_timeout,
|
|
145
|
-
sticky=self.sticky,
|
|
146
|
-
on_failure_job=on_failure_job,
|
|
147
|
-
concurrency=concurrency,
|
|
148
|
-
jobs=[
|
|
149
|
-
CreateWorkflowJobOpts(
|
|
150
|
-
name=self.function_name,
|
|
151
|
-
steps=[
|
|
152
|
-
self.to_step(),
|
|
153
|
-
],
|
|
154
|
-
)
|
|
155
|
-
],
|
|
156
|
-
default_priority=validated_priority,
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
def to_step(self) -> CreateWorkflowStepOpts:
|
|
160
|
-
return CreateWorkflowStepOpts(
|
|
161
|
-
readable_id=self.function_name,
|
|
162
|
-
action=self.get_action_name(),
|
|
163
|
-
timeout=self.function_timeout,
|
|
164
|
-
inputs="{}",
|
|
165
|
-
parents=[],
|
|
166
|
-
retries=self.function_retries,
|
|
167
|
-
rate_limits=self.function_rate_limits,
|
|
168
|
-
worker_labels=self.function_desired_worker_labels,
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
def get_action_name(self) -> str:
|
|
172
|
-
return self.function_namespace + ":" + self.function_name
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
class DurableContext(Context):
|
|
176
|
-
def run(
|
|
177
|
-
self,
|
|
178
|
-
function: str | Callable[[Context], Any],
|
|
179
|
-
input: dict[Any, Any] = {},
|
|
180
|
-
key: str | None = None,
|
|
181
|
-
options: ChildTriggerWorkflowOptions | None = None,
|
|
182
|
-
) -> "RunRef[T]":
|
|
183
|
-
worker_id = self.worker.id()
|
|
184
|
-
|
|
185
|
-
workflow_name = function
|
|
186
|
-
|
|
187
|
-
if not isinstance(function, str):
|
|
188
|
-
workflow_name = function.function_name
|
|
189
|
-
|
|
190
|
-
# if (
|
|
191
|
-
# options is not None
|
|
192
|
-
# and "sticky" in options
|
|
193
|
-
# and options["sticky"] == True
|
|
194
|
-
# and not self.worker.has_workflow(workflow_name)
|
|
195
|
-
# ):
|
|
196
|
-
# raise Exception(
|
|
197
|
-
# f"cannot run with sticky: workflow {workflow_name} is not registered on the worker"
|
|
198
|
-
# )
|
|
199
|
-
|
|
200
|
-
trigger_options = self._prepare_workflow_options(key, options, worker_id)
|
|
201
|
-
|
|
202
|
-
return self.admin_client.run(function, input, trigger_options)
|
hatchet_sdk/v0/v2/concurrency.py
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
from typing import Any, Callable
|
|
2
|
-
|
|
3
|
-
from hatchet_sdk.contracts.workflows_pb2 import ( # type: ignore[attr-defined]
|
|
4
|
-
ConcurrencyLimitStrategy,
|
|
5
|
-
)
|
|
6
|
-
from hatchet_sdk.v0.context.context import Context
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class ConcurrencyFunction:
|
|
10
|
-
def __init__(
|
|
11
|
-
self,
|
|
12
|
-
func: Callable[[Context], str],
|
|
13
|
-
name: str = "concurrency",
|
|
14
|
-
max_runs: int = 1,
|
|
15
|
-
limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
16
|
-
):
|
|
17
|
-
self.func = func
|
|
18
|
-
self.name = name
|
|
19
|
-
self.max_runs = max_runs
|
|
20
|
-
self.limit_strategy = limit_strategy
|
|
21
|
-
self.namespace = "default"
|
|
22
|
-
|
|
23
|
-
def set_namespace(self, namespace: str) -> None:
|
|
24
|
-
self.namespace = namespace
|
|
25
|
-
|
|
26
|
-
def get_action_name(self) -> str:
|
|
27
|
-
return self.namespace + ":" + self.name
|
|
28
|
-
|
|
29
|
-
def __call__(self, *args: Any, **kwargs: Any) -> str:
|
|
30
|
-
return self.func(*args, **kwargs)
|
|
31
|
-
|
|
32
|
-
def __str__(self) -> str:
|
|
33
|
-
return f"{self.name}({self.max_runs})"
|
|
34
|
-
|
|
35
|
-
def __repr__(self) -> str:
|
|
36
|
-
return f"{self.name}({self.max_runs})"
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
def concurrency(
|
|
40
|
-
name: str = "",
|
|
41
|
-
max_runs: int = 1,
|
|
42
|
-
limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
43
|
-
) -> Callable[[Callable[[Context], str]], ConcurrencyFunction]:
|
|
44
|
-
def inner(func: Callable[[Context], str]) -> ConcurrencyFunction:
|
|
45
|
-
return ConcurrencyFunction(func, name, max_runs, limit_strategy)
|
|
46
|
-
|
|
47
|
-
return inner
|
hatchet_sdk/v0/v2/hatchet.py
DELETED
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
from typing import Any, Callable, TypeVar, Union
|
|
2
|
-
|
|
3
|
-
from hatchet_sdk.contracts.workflows_pb2 import ( # type: ignore[attr-defined]
|
|
4
|
-
ConcurrencyLimitStrategy,
|
|
5
|
-
StickyStrategy,
|
|
6
|
-
)
|
|
7
|
-
from hatchet_sdk.v0 import Worker
|
|
8
|
-
from hatchet_sdk.v0.context.context import Context
|
|
9
|
-
from hatchet_sdk.v0.hatchet import Hatchet as HatchetV1
|
|
10
|
-
from hatchet_sdk.v0.hatchet import workflow
|
|
11
|
-
from hatchet_sdk.v0.labels import DesiredWorkerLabel
|
|
12
|
-
from hatchet_sdk.v0.rate_limit import RateLimit
|
|
13
|
-
from hatchet_sdk.v0.v2.callable import DurableContext, HatchetCallable
|
|
14
|
-
from hatchet_sdk.v0.v2.concurrency import ConcurrencyFunction
|
|
15
|
-
from hatchet_sdk.v0.worker.worker import register_on_worker
|
|
16
|
-
|
|
17
|
-
T = TypeVar("T")
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def function(
|
|
21
|
-
name: str = "",
|
|
22
|
-
auto_register: bool = True,
|
|
23
|
-
on_events: list[str] | None = None,
|
|
24
|
-
on_crons: list[str] | None = None,
|
|
25
|
-
version: str = "",
|
|
26
|
-
timeout: str = "60m",
|
|
27
|
-
schedule_timeout: str = "5m",
|
|
28
|
-
sticky: StickyStrategy = None,
|
|
29
|
-
retries: int = 0,
|
|
30
|
-
rate_limits: list[RateLimit] | None = None,
|
|
31
|
-
desired_worker_labels: dict[str, DesiredWorkerLabel] = {},
|
|
32
|
-
concurrency: ConcurrencyFunction | None = None,
|
|
33
|
-
on_failure: Union["HatchetCallable[T]", None] = None,
|
|
34
|
-
default_priority: int | None = None,
|
|
35
|
-
) -> Callable[[Callable[[Context], str]], HatchetCallable[T]]:
|
|
36
|
-
def inner(func: Callable[[Context], T]) -> HatchetCallable[T]:
|
|
37
|
-
return HatchetCallable(
|
|
38
|
-
func=func,
|
|
39
|
-
name=name,
|
|
40
|
-
auto_register=auto_register,
|
|
41
|
-
on_events=on_events,
|
|
42
|
-
on_crons=on_crons,
|
|
43
|
-
version=version,
|
|
44
|
-
timeout=timeout,
|
|
45
|
-
schedule_timeout=schedule_timeout,
|
|
46
|
-
sticky=sticky,
|
|
47
|
-
retries=retries,
|
|
48
|
-
rate_limits=rate_limits,
|
|
49
|
-
desired_worker_labels=desired_worker_labels,
|
|
50
|
-
concurrency=concurrency,
|
|
51
|
-
on_failure=on_failure,
|
|
52
|
-
default_priority=default_priority,
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
return inner
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
def durable(
|
|
59
|
-
name: str = "",
|
|
60
|
-
auto_register: bool = True,
|
|
61
|
-
on_events: list[str] | None = None,
|
|
62
|
-
on_crons: list[str] | None = None,
|
|
63
|
-
version: str = "",
|
|
64
|
-
timeout: str = "60m",
|
|
65
|
-
schedule_timeout: str = "5m",
|
|
66
|
-
sticky: StickyStrategy = None,
|
|
67
|
-
retries: int = 0,
|
|
68
|
-
rate_limits: list[RateLimit] | None = None,
|
|
69
|
-
desired_worker_labels: dict[str, DesiredWorkerLabel] = {},
|
|
70
|
-
concurrency: ConcurrencyFunction | None = None,
|
|
71
|
-
on_failure: HatchetCallable[T] | None = None,
|
|
72
|
-
default_priority: int | None = None,
|
|
73
|
-
) -> Callable[[HatchetCallable[T]], HatchetCallable[T]]:
|
|
74
|
-
def inner(func: HatchetCallable[T]) -> HatchetCallable[T]:
|
|
75
|
-
func.durable = True
|
|
76
|
-
|
|
77
|
-
f = function(
|
|
78
|
-
name=name,
|
|
79
|
-
auto_register=auto_register,
|
|
80
|
-
on_events=on_events,
|
|
81
|
-
on_crons=on_crons,
|
|
82
|
-
version=version,
|
|
83
|
-
timeout=timeout,
|
|
84
|
-
schedule_timeout=schedule_timeout,
|
|
85
|
-
sticky=sticky,
|
|
86
|
-
retries=retries,
|
|
87
|
-
rate_limits=rate_limits,
|
|
88
|
-
desired_worker_labels=desired_worker_labels,
|
|
89
|
-
concurrency=concurrency,
|
|
90
|
-
on_failure=on_failure,
|
|
91
|
-
default_priority=default_priority,
|
|
92
|
-
)
|
|
93
|
-
|
|
94
|
-
resp = f(func)
|
|
95
|
-
|
|
96
|
-
resp.durable = True
|
|
97
|
-
|
|
98
|
-
return resp
|
|
99
|
-
|
|
100
|
-
return inner
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def concurrency(
|
|
104
|
-
name: str = "concurrency",
|
|
105
|
-
max_runs: int = 1,
|
|
106
|
-
limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
|
|
107
|
-
) -> Callable[[Callable[[Context], str]], ConcurrencyFunction]:
|
|
108
|
-
def inner(func: Callable[[Context], str]) -> ConcurrencyFunction:
|
|
109
|
-
return ConcurrencyFunction(func, name, max_runs, limit_strategy)
|
|
110
|
-
|
|
111
|
-
return inner
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
class Hatchet(HatchetV1):
|
|
115
|
-
dag = staticmethod(workflow)
|
|
116
|
-
concurrency = staticmethod(concurrency)
|
|
117
|
-
|
|
118
|
-
functions: list[HatchetCallable[T]] = []
|
|
119
|
-
|
|
120
|
-
def function(
|
|
121
|
-
self,
|
|
122
|
-
name: str = "",
|
|
123
|
-
auto_register: bool = True,
|
|
124
|
-
on_events: list[str] | None = None,
|
|
125
|
-
on_crons: list[str] | None = None,
|
|
126
|
-
version: str = "",
|
|
127
|
-
timeout: str = "60m",
|
|
128
|
-
schedule_timeout: str = "5m",
|
|
129
|
-
retries: int = 0,
|
|
130
|
-
rate_limits: list[RateLimit] | None = None,
|
|
131
|
-
desired_worker_labels: dict[str, DesiredWorkerLabel] = {},
|
|
132
|
-
concurrency: ConcurrencyFunction | None = None,
|
|
133
|
-
on_failure: Union["HatchetCallable[T]", None] = None,
|
|
134
|
-
default_priority: int | None = None,
|
|
135
|
-
) -> Callable[[Callable[[Context], Any]], Callable[[Context], Any]]:
|
|
136
|
-
resp = function(
|
|
137
|
-
name=name,
|
|
138
|
-
auto_register=auto_register,
|
|
139
|
-
on_events=on_events,
|
|
140
|
-
on_crons=on_crons,
|
|
141
|
-
version=version,
|
|
142
|
-
timeout=timeout,
|
|
143
|
-
schedule_timeout=schedule_timeout,
|
|
144
|
-
retries=retries,
|
|
145
|
-
rate_limits=rate_limits,
|
|
146
|
-
desired_worker_labels=desired_worker_labels,
|
|
147
|
-
concurrency=concurrency,
|
|
148
|
-
on_failure=on_failure,
|
|
149
|
-
default_priority=default_priority,
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
def wrapper(func: Callable[[Context], str]) -> HatchetCallable[T]:
|
|
153
|
-
wrapped_resp = resp(func)
|
|
154
|
-
|
|
155
|
-
if wrapped_resp.function_auto_register:
|
|
156
|
-
self.functions.append(wrapped_resp)
|
|
157
|
-
|
|
158
|
-
wrapped_resp.with_namespace(self._client.config.namespace)
|
|
159
|
-
|
|
160
|
-
return wrapped_resp
|
|
161
|
-
|
|
162
|
-
return wrapper
|
|
163
|
-
|
|
164
|
-
def durable(
|
|
165
|
-
self,
|
|
166
|
-
name: str = "",
|
|
167
|
-
auto_register: bool = True,
|
|
168
|
-
on_events: list[str] | None = None,
|
|
169
|
-
on_crons: list[str] | None = None,
|
|
170
|
-
version: str = "",
|
|
171
|
-
timeout: str = "60m",
|
|
172
|
-
schedule_timeout: str = "5m",
|
|
173
|
-
sticky: StickyStrategy = None,
|
|
174
|
-
retries: int = 0,
|
|
175
|
-
rate_limits: list[RateLimit] | None = None,
|
|
176
|
-
desired_worker_labels: dict[str, DesiredWorkerLabel] = {},
|
|
177
|
-
concurrency: ConcurrencyFunction | None = None,
|
|
178
|
-
on_failure: Union["HatchetCallable[T]", None] = None,
|
|
179
|
-
default_priority: int | None = None,
|
|
180
|
-
) -> Callable[[Callable[[DurableContext], Any]], Callable[[DurableContext], Any]]:
|
|
181
|
-
resp = durable(
|
|
182
|
-
name=name,
|
|
183
|
-
auto_register=auto_register,
|
|
184
|
-
on_events=on_events,
|
|
185
|
-
on_crons=on_crons,
|
|
186
|
-
version=version,
|
|
187
|
-
timeout=timeout,
|
|
188
|
-
schedule_timeout=schedule_timeout,
|
|
189
|
-
sticky=sticky,
|
|
190
|
-
retries=retries,
|
|
191
|
-
rate_limits=rate_limits,
|
|
192
|
-
desired_worker_labels=desired_worker_labels,
|
|
193
|
-
concurrency=concurrency,
|
|
194
|
-
on_failure=on_failure,
|
|
195
|
-
default_priority=default_priority,
|
|
196
|
-
)
|
|
197
|
-
|
|
198
|
-
def wrapper(func: HatchetCallable[T]) -> HatchetCallable[T]:
|
|
199
|
-
wrapped_resp = resp(func)
|
|
200
|
-
|
|
201
|
-
if wrapped_resp.function_auto_register:
|
|
202
|
-
self.functions.append(wrapped_resp)
|
|
203
|
-
|
|
204
|
-
wrapped_resp.with_namespace(self._client.config.namespace)
|
|
205
|
-
|
|
206
|
-
return wrapped_resp
|
|
207
|
-
|
|
208
|
-
return wrapper
|
|
209
|
-
|
|
210
|
-
def worker(
|
|
211
|
-
self, name: str, max_runs: int | None = None, labels: dict[str, str | int] = {}
|
|
212
|
-
):
|
|
213
|
-
worker = Worker(
|
|
214
|
-
name=name,
|
|
215
|
-
max_runs=max_runs,
|
|
216
|
-
labels=labels,
|
|
217
|
-
config=self._client.config,
|
|
218
|
-
debug=self._client.debug,
|
|
219
|
-
)
|
|
220
|
-
|
|
221
|
-
for func in self.functions:
|
|
222
|
-
register_on_worker(func, worker)
|
|
223
|
-
|
|
224
|
-
return worker
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .worker import Worker, WorkerStartOptions, WorkerStatus
|