hatchet-sdk 1.11.1__py3-none-any.whl → 1.12.1__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/__init__.py +2 -0
- hatchet_sdk/client.py +2 -0
- hatchet_sdk/clients/events.py +42 -3
- hatchet_sdk/clients/rest/__init__.py +5 -0
- hatchet_sdk/clients/rest/api/event_api.py +490 -0
- hatchet_sdk/clients/rest/api/filter_api.py +339 -0
- hatchet_sdk/clients/rest/api/tenant_api.py +275 -0
- hatchet_sdk/clients/rest/api/workflow_runs_api.py +310 -0
- hatchet_sdk/clients/rest/models/__init__.py +5 -0
- hatchet_sdk/clients/rest/models/create_tenant_request.py +22 -2
- hatchet_sdk/clients/rest/models/tenant.py +6 -0
- hatchet_sdk/clients/rest/models/tenant_ui_version.py +37 -0
- hatchet_sdk/clients/rest/models/update_tenant_request.py +6 -0
- hatchet_sdk/clients/rest/models/v1_event.py +42 -0
- hatchet_sdk/clients/rest/models/v1_event_triggered_run.py +94 -0
- hatchet_sdk/clients/rest/models/v1_update_filter_request.py +98 -0
- hatchet_sdk/contracts/v1/workflows_pb2.py +26 -24
- hatchet_sdk/contracts/v1/workflows_pb2.pyi +14 -2
- hatchet_sdk/features/filters.py +36 -0
- hatchet_sdk/features/runs.py +22 -3
- hatchet_sdk/features/tenant.py +32 -0
- hatchet_sdk/hatchet.py +51 -8
- hatchet_sdk/runnables/action.py +1 -1
- hatchet_sdk/runnables/types.py +22 -4
- hatchet_sdk/runnables/workflow.py +413 -188
- hatchet_sdk/waits.py +2 -2
- {hatchet_sdk-1.11.1.dist-info → hatchet_sdk-1.12.1.dist-info}/METADATA +1 -1
- {hatchet_sdk-1.11.1.dist-info → hatchet_sdk-1.12.1.dist-info}/RECORD +30 -27
- hatchet_sdk/runnables/standalone.py +0 -391
- {hatchet_sdk-1.11.1.dist-info → hatchet_sdk-1.12.1.dist-info}/WHEEL +0 -0
- {hatchet_sdk-1.11.1.dist-info → hatchet_sdk-1.12.1.dist-info}/entry_points.txt +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import asyncio
|
|
2
|
-
from datetime import datetime, timedelta
|
|
2
|
+
from datetime import datetime, timedelta, timezone
|
|
3
3
|
from functools import cached_property
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, cast
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Callable, Generic, TypeVar, cast, get_type_hints
|
|
5
5
|
|
|
6
6
|
from google.protobuf import timestamp_pb2
|
|
7
7
|
from pydantic import BaseModel, model_validator
|
|
@@ -12,6 +12,7 @@ from hatchet_sdk.clients.admin import (
|
|
|
12
12
|
WorkflowRunTriggerConfig,
|
|
13
13
|
)
|
|
14
14
|
from hatchet_sdk.clients.rest.models.cron_workflows import CronWorkflows
|
|
15
|
+
from hatchet_sdk.clients.rest.models.v1_filter import V1Filter
|
|
15
16
|
from hatchet_sdk.clients.rest.models.v1_task_status import V1TaskStatus
|
|
16
17
|
from hatchet_sdk.clients.rest.models.v1_task_summary import V1TaskSummary
|
|
17
18
|
from hatchet_sdk.context.context import Context, DurableContext
|
|
@@ -22,7 +23,6 @@ from hatchet_sdk.contracts.v1.workflows_pb2 import (
|
|
|
22
23
|
from hatchet_sdk.contracts.v1.workflows_pb2 import StickyStrategy as StickyStrategyProto
|
|
23
24
|
from hatchet_sdk.contracts.workflows_pb2 import WorkflowVersion
|
|
24
25
|
from hatchet_sdk.labels import DesiredWorkerLabel
|
|
25
|
-
from hatchet_sdk.logger import logger
|
|
26
26
|
from hatchet_sdk.rate_limit import RateLimit
|
|
27
27
|
from hatchet_sdk.runnables.task import Task
|
|
28
28
|
from hatchet_sdk.runnables.types import (
|
|
@@ -36,13 +36,16 @@ from hatchet_sdk.runnables.types import (
|
|
|
36
36
|
)
|
|
37
37
|
from hatchet_sdk.utils.proto_enums import convert_python_enum_to_proto
|
|
38
38
|
from hatchet_sdk.utils.timedelta_to_expression import Duration
|
|
39
|
-
from hatchet_sdk.utils.typing import
|
|
39
|
+
from hatchet_sdk.utils.typing import (
|
|
40
|
+
CoroutineLike,
|
|
41
|
+
JSONSerializableMapping,
|
|
42
|
+
is_basemodel_subclass,
|
|
43
|
+
)
|
|
40
44
|
from hatchet_sdk.waits import Condition, OrGroup
|
|
41
45
|
from hatchet_sdk.workflow_run import WorkflowRunRef
|
|
42
46
|
|
|
43
47
|
if TYPE_CHECKING:
|
|
44
48
|
from hatchet_sdk import Hatchet
|
|
45
|
-
from hatchet_sdk.runnables.standalone import Standalone
|
|
46
49
|
|
|
47
50
|
|
|
48
51
|
T = TypeVar("T")
|
|
@@ -190,10 +193,13 @@ class BaseWorkflow(Generic[TWorkflowInput]):
|
|
|
190
193
|
## TODO: Fix this
|
|
191
194
|
cron_input=None,
|
|
192
195
|
on_failure_task=on_failure_task,
|
|
193
|
-
sticky=convert_python_enum_to_proto(
|
|
196
|
+
sticky=convert_python_enum_to_proto(
|
|
197
|
+
self.config.sticky, StickyStrategyProto
|
|
198
|
+
), # type: ignore[arg-type]
|
|
194
199
|
concurrency=_concurrency,
|
|
195
200
|
concurrency_arr=_concurrency_arr,
|
|
196
201
|
default_priority=self.config.default_priority,
|
|
202
|
+
default_filters=[f.to_proto() for f in self.config.default_filters],
|
|
197
203
|
)
|
|
198
204
|
|
|
199
205
|
def _get_workflow_input(self, ctx: Context) -> TWorkflowInput:
|
|
@@ -214,12 +220,11 @@ class BaseWorkflow(Generic[TWorkflowInput]):
|
|
|
214
220
|
|
|
215
221
|
return tasks
|
|
216
222
|
|
|
217
|
-
@property
|
|
218
|
-
def is_durable(self) -> bool:
|
|
219
|
-
return any(task.is_durable for task in self.tasks)
|
|
220
|
-
|
|
221
223
|
@property
|
|
222
224
|
def name(self) -> str:
|
|
225
|
+
"""
|
|
226
|
+
The (namespaced) name of the workflow.
|
|
227
|
+
"""
|
|
223
228
|
return self.client.config.namespace + self.config.name
|
|
224
229
|
|
|
225
230
|
def create_bulk_run_item(
|
|
@@ -272,6 +277,236 @@ class BaseWorkflow(Generic[TWorkflowInput]):
|
|
|
272
277
|
|
|
273
278
|
return workflow.metadata.id
|
|
274
279
|
|
|
280
|
+
def list_runs(
|
|
281
|
+
self,
|
|
282
|
+
since: datetime | None = None,
|
|
283
|
+
until: datetime | None = None,
|
|
284
|
+
limit: int = 100,
|
|
285
|
+
offset: int | None = None,
|
|
286
|
+
statuses: list[V1TaskStatus] | None = None,
|
|
287
|
+
additional_metadata: dict[str, str] | None = None,
|
|
288
|
+
worker_id: str | None = None,
|
|
289
|
+
parent_task_external_id: str | None = None,
|
|
290
|
+
only_tasks: bool = False,
|
|
291
|
+
triggering_event_external_id: str | None = None,
|
|
292
|
+
) -> list[V1TaskSummary]:
|
|
293
|
+
"""
|
|
294
|
+
List runs of the workflow.
|
|
295
|
+
|
|
296
|
+
:param since: The start time for the runs to be listed.
|
|
297
|
+
:param until: The end time for the runs to be listed.
|
|
298
|
+
:param limit: The maximum number of runs to be listed.
|
|
299
|
+
:param offset: The offset for pagination.
|
|
300
|
+
:param statuses: The statuses of the runs to be listed.
|
|
301
|
+
:param additional_metadata: Additional metadata for filtering the runs.
|
|
302
|
+
:param worker_id: The ID of the worker that ran the tasks.
|
|
303
|
+
:param parent_task_external_id: The external ID of the parent task.
|
|
304
|
+
:param only_tasks: Whether to list only task runs.
|
|
305
|
+
:param triggering_event_external_id: The event id that triggered the task run.
|
|
306
|
+
|
|
307
|
+
:returns: A list of `V1TaskSummary` objects representing the runs of the workflow.
|
|
308
|
+
"""
|
|
309
|
+
response = self.client.runs.list(
|
|
310
|
+
workflow_ids=[self.id],
|
|
311
|
+
since=since or datetime.now(tz=timezone.utc) - timedelta(days=1),
|
|
312
|
+
only_tasks=only_tasks,
|
|
313
|
+
offset=offset,
|
|
314
|
+
limit=limit,
|
|
315
|
+
statuses=statuses,
|
|
316
|
+
until=until,
|
|
317
|
+
additional_metadata=additional_metadata,
|
|
318
|
+
worker_id=worker_id,
|
|
319
|
+
parent_task_external_id=parent_task_external_id,
|
|
320
|
+
triggering_event_external_id=triggering_event_external_id,
|
|
321
|
+
)
|
|
322
|
+
|
|
323
|
+
return response.rows
|
|
324
|
+
|
|
325
|
+
async def aio_list_runs(
|
|
326
|
+
self,
|
|
327
|
+
since: datetime | None = None,
|
|
328
|
+
until: datetime | None = None,
|
|
329
|
+
limit: int = 100,
|
|
330
|
+
offset: int | None = None,
|
|
331
|
+
statuses: list[V1TaskStatus] | None = None,
|
|
332
|
+
additional_metadata: dict[str, str] | None = None,
|
|
333
|
+
worker_id: str | None = None,
|
|
334
|
+
parent_task_external_id: str | None = None,
|
|
335
|
+
only_tasks: bool = False,
|
|
336
|
+
triggering_event_external_id: str | None = None,
|
|
337
|
+
) -> list[V1TaskSummary]:
|
|
338
|
+
"""
|
|
339
|
+
List runs of the workflow.
|
|
340
|
+
|
|
341
|
+
:param since: The start time for the runs to be listed.
|
|
342
|
+
:param until: The end time for the runs to be listed.
|
|
343
|
+
:param limit: The maximum number of runs to be listed.
|
|
344
|
+
:param offset: The offset for pagination.
|
|
345
|
+
:param statuses: The statuses of the runs to be listed.
|
|
346
|
+
:param additional_metadata: Additional metadata for filtering the runs.
|
|
347
|
+
:param worker_id: The ID of the worker that ran the tasks.
|
|
348
|
+
:param parent_task_external_id: The external ID of the parent task.
|
|
349
|
+
:param only_tasks: Whether to list only task runs.
|
|
350
|
+
:param triggering_event_external_id: The event id that triggered the task run.
|
|
351
|
+
|
|
352
|
+
:returns: A list of `V1TaskSummary` objects representing the runs of the workflow.
|
|
353
|
+
"""
|
|
354
|
+
return await asyncio.to_thread(
|
|
355
|
+
self.list_runs,
|
|
356
|
+
since=since or datetime.now(tz=timezone.utc) - timedelta(days=1),
|
|
357
|
+
only_tasks=only_tasks,
|
|
358
|
+
offset=offset,
|
|
359
|
+
limit=limit,
|
|
360
|
+
statuses=statuses,
|
|
361
|
+
until=until,
|
|
362
|
+
additional_metadata=additional_metadata,
|
|
363
|
+
worker_id=worker_id,
|
|
364
|
+
parent_task_external_id=parent_task_external_id,
|
|
365
|
+
triggering_event_external_id=triggering_event_external_id,
|
|
366
|
+
)
|
|
367
|
+
|
|
368
|
+
def create_filter(
|
|
369
|
+
self,
|
|
370
|
+
expression: str,
|
|
371
|
+
scope: str,
|
|
372
|
+
payload: JSONSerializableMapping = {},
|
|
373
|
+
) -> V1Filter:
|
|
374
|
+
"""
|
|
375
|
+
Create a new filter.
|
|
376
|
+
|
|
377
|
+
:param expression: The expression to evaluate for the filter.
|
|
378
|
+
:param scope: The scope for the filter.
|
|
379
|
+
:param payload: The payload to send with the filter.
|
|
380
|
+
|
|
381
|
+
:return: The created filter.
|
|
382
|
+
"""
|
|
383
|
+
return self.client.filters.create(
|
|
384
|
+
workflow_id=self.id,
|
|
385
|
+
expression=expression,
|
|
386
|
+
scope=scope,
|
|
387
|
+
payload=payload,
|
|
388
|
+
)
|
|
389
|
+
|
|
390
|
+
async def aio_create_filter(
|
|
391
|
+
self,
|
|
392
|
+
expression: str,
|
|
393
|
+
scope: str,
|
|
394
|
+
payload: JSONSerializableMapping = {},
|
|
395
|
+
) -> V1Filter:
|
|
396
|
+
"""
|
|
397
|
+
Create a new filter.
|
|
398
|
+
|
|
399
|
+
:param expression: The expression to evaluate for the filter.
|
|
400
|
+
:param scope: The scope for the filter.
|
|
401
|
+
:param payload: The payload to send with the filter.
|
|
402
|
+
|
|
403
|
+
:return: The created filter.
|
|
404
|
+
"""
|
|
405
|
+
return await self.client.filters.aio_create(
|
|
406
|
+
workflow_id=self.id,
|
|
407
|
+
expression=expression,
|
|
408
|
+
scope=scope,
|
|
409
|
+
payload=payload,
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
def schedule(
|
|
413
|
+
self,
|
|
414
|
+
run_at: datetime,
|
|
415
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
416
|
+
options: ScheduleTriggerWorkflowOptions = ScheduleTriggerWorkflowOptions(),
|
|
417
|
+
) -> WorkflowVersion:
|
|
418
|
+
"""
|
|
419
|
+
Schedule a workflow to run at a specific time.
|
|
420
|
+
|
|
421
|
+
:param run_at: The time at which to schedule the workflow.
|
|
422
|
+
:param input: The input data for the workflow.
|
|
423
|
+
:param options: Additional options for workflow execution.
|
|
424
|
+
:returns: A `WorkflowVersion` object representing the scheduled workflow.
|
|
425
|
+
"""
|
|
426
|
+
return self.client._client.admin.schedule_workflow(
|
|
427
|
+
name=self.config.name,
|
|
428
|
+
schedules=cast(list[datetime | timestamp_pb2.Timestamp], [run_at]),
|
|
429
|
+
input=self._serialize_input(input),
|
|
430
|
+
options=options,
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
async def aio_schedule(
|
|
434
|
+
self,
|
|
435
|
+
run_at: datetime,
|
|
436
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
437
|
+
options: ScheduleTriggerWorkflowOptions = ScheduleTriggerWorkflowOptions(),
|
|
438
|
+
) -> WorkflowVersion:
|
|
439
|
+
"""
|
|
440
|
+
Schedule a workflow to run at a specific time.
|
|
441
|
+
|
|
442
|
+
:param run_at: The time at which to schedule the workflow.
|
|
443
|
+
:param input: The input data for the workflow.
|
|
444
|
+
:param options: Additional options for workflow execution.
|
|
445
|
+
:returns: A `WorkflowVersion` object representing the scheduled workflow.
|
|
446
|
+
"""
|
|
447
|
+
return await self.client._client.admin.aio_schedule_workflow(
|
|
448
|
+
name=self.config.name,
|
|
449
|
+
schedules=cast(list[datetime | timestamp_pb2.Timestamp], [run_at]),
|
|
450
|
+
input=self._serialize_input(input),
|
|
451
|
+
options=options,
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
def create_cron(
|
|
455
|
+
self,
|
|
456
|
+
cron_name: str,
|
|
457
|
+
expression: str,
|
|
458
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
459
|
+
additional_metadata: JSONSerializableMapping = {},
|
|
460
|
+
priority: int | None = None,
|
|
461
|
+
) -> CronWorkflows:
|
|
462
|
+
"""
|
|
463
|
+
Create a cron job for the workflow.
|
|
464
|
+
|
|
465
|
+
:param cron_name: The name of the cron job.
|
|
466
|
+
:param expression: The cron expression that defines the schedule for the cron job.
|
|
467
|
+
:param input: The input data for the workflow.
|
|
468
|
+
:param additional_metadata: Additional metadata for the cron job.
|
|
469
|
+
:param priority: The priority of the cron job. Must be between 1 and 3, inclusive.
|
|
470
|
+
|
|
471
|
+
:returns: A `CronWorkflows` object representing the created cron job.
|
|
472
|
+
"""
|
|
473
|
+
return self.client.cron.create(
|
|
474
|
+
workflow_name=self.config.name,
|
|
475
|
+
cron_name=cron_name,
|
|
476
|
+
expression=expression,
|
|
477
|
+
input=self._serialize_input(input),
|
|
478
|
+
additional_metadata=additional_metadata,
|
|
479
|
+
priority=priority,
|
|
480
|
+
)
|
|
481
|
+
|
|
482
|
+
async def aio_create_cron(
|
|
483
|
+
self,
|
|
484
|
+
cron_name: str,
|
|
485
|
+
expression: str,
|
|
486
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
487
|
+
additional_metadata: JSONSerializableMapping = {},
|
|
488
|
+
priority: int | None = None,
|
|
489
|
+
) -> CronWorkflows:
|
|
490
|
+
"""
|
|
491
|
+
Create a cron job for the workflow.
|
|
492
|
+
|
|
493
|
+
:param cron_name: The name of the cron job.
|
|
494
|
+
:param expression: The cron expression that defines the schedule for the cron job.
|
|
495
|
+
:param input: The input data for the workflow.
|
|
496
|
+
:param additional_metadata: Additional metadata for the cron job.
|
|
497
|
+
:param priority: The priority of the cron job. Must be between 1 and 3, inclusive.
|
|
498
|
+
|
|
499
|
+
:returns: A `CronWorkflows` object representing the created cron job.
|
|
500
|
+
"""
|
|
501
|
+
return await self.client.cron.aio_create(
|
|
502
|
+
workflow_name=self.config.name,
|
|
503
|
+
cron_name=cron_name,
|
|
504
|
+
expression=expression,
|
|
505
|
+
input=self._serialize_input(input),
|
|
506
|
+
additional_metadata=additional_metadata,
|
|
507
|
+
priority=priority,
|
|
508
|
+
)
|
|
509
|
+
|
|
275
510
|
|
|
276
511
|
class Workflow(BaseWorkflow[TWorkflowInput]):
|
|
277
512
|
"""
|
|
@@ -465,104 +700,6 @@ class Workflow(BaseWorkflow[TWorkflowInput]):
|
|
|
465
700
|
workflows=workflows,
|
|
466
701
|
)
|
|
467
702
|
|
|
468
|
-
def schedule(
|
|
469
|
-
self,
|
|
470
|
-
run_at: datetime,
|
|
471
|
-
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
472
|
-
options: ScheduleTriggerWorkflowOptions = ScheduleTriggerWorkflowOptions(),
|
|
473
|
-
) -> WorkflowVersion:
|
|
474
|
-
"""
|
|
475
|
-
Schedule a workflow to run at a specific time.
|
|
476
|
-
|
|
477
|
-
:param run_at: The time at which to schedule the workflow.
|
|
478
|
-
:param input: The input data for the workflow.
|
|
479
|
-
:param options: Additional options for workflow execution.
|
|
480
|
-
:returns: A `WorkflowVersion` object representing the scheduled workflow.
|
|
481
|
-
"""
|
|
482
|
-
return self.client._client.admin.schedule_workflow(
|
|
483
|
-
name=self.config.name,
|
|
484
|
-
schedules=cast(list[datetime | timestamp_pb2.Timestamp], [run_at]),
|
|
485
|
-
input=self._serialize_input(input),
|
|
486
|
-
options=options,
|
|
487
|
-
)
|
|
488
|
-
|
|
489
|
-
async def aio_schedule(
|
|
490
|
-
self,
|
|
491
|
-
run_at: datetime,
|
|
492
|
-
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
493
|
-
options: ScheduleTriggerWorkflowOptions = ScheduleTriggerWorkflowOptions(),
|
|
494
|
-
) -> WorkflowVersion:
|
|
495
|
-
"""
|
|
496
|
-
Schedule a workflow to run at a specific time.
|
|
497
|
-
|
|
498
|
-
:param run_at: The time at which to schedule the workflow.
|
|
499
|
-
:param input: The input data for the workflow.
|
|
500
|
-
:param options: Additional options for workflow execution.
|
|
501
|
-
:returns: A `WorkflowVersion` object representing the scheduled workflow.
|
|
502
|
-
"""
|
|
503
|
-
return await self.client._client.admin.aio_schedule_workflow(
|
|
504
|
-
name=self.config.name,
|
|
505
|
-
schedules=cast(list[datetime | timestamp_pb2.Timestamp], [run_at]),
|
|
506
|
-
input=self._serialize_input(input),
|
|
507
|
-
options=options,
|
|
508
|
-
)
|
|
509
|
-
|
|
510
|
-
def create_cron(
|
|
511
|
-
self,
|
|
512
|
-
cron_name: str,
|
|
513
|
-
expression: str,
|
|
514
|
-
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
515
|
-
additional_metadata: JSONSerializableMapping = {},
|
|
516
|
-
priority: int | None = None,
|
|
517
|
-
) -> CronWorkflows:
|
|
518
|
-
"""
|
|
519
|
-
Create a cron job for the workflow.
|
|
520
|
-
|
|
521
|
-
:param cron_name: The name of the cron job.
|
|
522
|
-
:param expression: The cron expression that defines the schedule for the cron job.
|
|
523
|
-
:param input: The input data for the workflow.
|
|
524
|
-
:param additional_metadata: Additional metadata for the cron job.
|
|
525
|
-
:param priority: The priority of the cron job. Must be between 1 and 3, inclusive.
|
|
526
|
-
|
|
527
|
-
:returns: A `CronWorkflows` object representing the created cron job.
|
|
528
|
-
"""
|
|
529
|
-
return self.client.cron.create(
|
|
530
|
-
workflow_name=self.config.name,
|
|
531
|
-
cron_name=cron_name,
|
|
532
|
-
expression=expression,
|
|
533
|
-
input=self._serialize_input(input),
|
|
534
|
-
additional_metadata=additional_metadata,
|
|
535
|
-
priority=priority,
|
|
536
|
-
)
|
|
537
|
-
|
|
538
|
-
async def aio_create_cron(
|
|
539
|
-
self,
|
|
540
|
-
cron_name: str,
|
|
541
|
-
expression: str,
|
|
542
|
-
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
543
|
-
additional_metadata: JSONSerializableMapping = {},
|
|
544
|
-
priority: int | None = None,
|
|
545
|
-
) -> CronWorkflows:
|
|
546
|
-
"""
|
|
547
|
-
Create a cron job for the workflow.
|
|
548
|
-
|
|
549
|
-
:param cron_name: The name of the cron job.
|
|
550
|
-
:param expression: The cron expression that defines the schedule for the cron job.
|
|
551
|
-
:param input: The input data for the workflow.
|
|
552
|
-
:param additional_metadata: Additional metadata for the cron job.
|
|
553
|
-
:param priority: The priority of the cron job. Must be between 1 and 3, inclusive.
|
|
554
|
-
|
|
555
|
-
:returns: A `CronWorkflows` object representing the created cron job.
|
|
556
|
-
"""
|
|
557
|
-
return await self.client.cron.aio_create(
|
|
558
|
-
workflow_name=self.config.name,
|
|
559
|
-
cron_name=cron_name,
|
|
560
|
-
expression=expression,
|
|
561
|
-
input=self._serialize_input(input),
|
|
562
|
-
additional_metadata=additional_metadata,
|
|
563
|
-
priority=priority,
|
|
564
|
-
)
|
|
565
|
-
|
|
566
703
|
def _parse_task_name(
|
|
567
704
|
self,
|
|
568
705
|
name: str | None,
|
|
@@ -922,98 +1059,186 @@ class Workflow(BaseWorkflow[TWorkflowInput]):
|
|
|
922
1059
|
case _:
|
|
923
1060
|
raise ValueError("Invalid task type")
|
|
924
1061
|
|
|
925
|
-
|
|
1062
|
+
|
|
1063
|
+
class TaskRunRef(Generic[TWorkflowInput, R]):
|
|
1064
|
+
def __init__(
|
|
926
1065
|
self,
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
1066
|
+
standalone: "Standalone[TWorkflowInput, R]",
|
|
1067
|
+
workflow_run_ref: WorkflowRunRef,
|
|
1068
|
+
):
|
|
1069
|
+
self._s = standalone
|
|
1070
|
+
self._wrr = workflow_run_ref
|
|
1071
|
+
|
|
1072
|
+
self.workflow_run_id = workflow_run_ref.workflow_run_id
|
|
1073
|
+
|
|
1074
|
+
def __str__(self) -> str:
|
|
1075
|
+
return self.workflow_run_id
|
|
1076
|
+
|
|
1077
|
+
async def aio_result(self) -> R:
|
|
1078
|
+
result = await self._wrr.workflow_run_listener.aio_result(
|
|
1079
|
+
self._wrr.workflow_run_id
|
|
1080
|
+
)
|
|
1081
|
+
return self._s._extract_result(result)
|
|
1082
|
+
|
|
1083
|
+
def result(self) -> R:
|
|
1084
|
+
result = self._wrr.result()
|
|
1085
|
+
|
|
1086
|
+
return self._s._extract_result(result)
|
|
1087
|
+
|
|
1088
|
+
|
|
1089
|
+
class Standalone(BaseWorkflow[TWorkflowInput], Generic[TWorkflowInput, R]):
|
|
1090
|
+
def __init__(
|
|
1091
|
+
self, workflow: Workflow[TWorkflowInput], task: Task[TWorkflowInput, R]
|
|
1092
|
+
) -> None:
|
|
1093
|
+
super().__init__(config=workflow.config, client=workflow.client)
|
|
1094
|
+
|
|
1095
|
+
## NOTE: This is a hack to assign the task back to the base workflow,
|
|
1096
|
+
## since the decorator to mutate the tasks is not being called.
|
|
1097
|
+
self._default_tasks = [task]
|
|
1098
|
+
|
|
1099
|
+
self._workflow = workflow
|
|
1100
|
+
self._task = task
|
|
1101
|
+
|
|
1102
|
+
return_type = get_type_hints(self._task.fn).get("return")
|
|
1103
|
+
|
|
1104
|
+
self._output_validator = (
|
|
1105
|
+
return_type if is_basemodel_subclass(return_type) else None
|
|
1106
|
+
)
|
|
1107
|
+
|
|
1108
|
+
self.config = self._workflow.config
|
|
1109
|
+
|
|
1110
|
+
def _extract_result(self, result: dict[str, Any]) -> R:
|
|
1111
|
+
output = result.get(self._task.name)
|
|
1112
|
+
|
|
1113
|
+
if not self._output_validator:
|
|
1114
|
+
return cast(R, output)
|
|
1115
|
+
|
|
1116
|
+
return cast(R, self._output_validator.model_validate(output))
|
|
1117
|
+
|
|
1118
|
+
def run(
|
|
1119
|
+
self,
|
|
1120
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
1121
|
+
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
1122
|
+
) -> R:
|
|
938
1123
|
"""
|
|
939
|
-
|
|
1124
|
+
Synchronously trigger a workflow run without waiting for it to complete.
|
|
1125
|
+
This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.
|
|
940
1126
|
|
|
941
|
-
:param
|
|
942
|
-
:param
|
|
943
|
-
:param limit: The maximum number of runs to be listed.
|
|
944
|
-
:param offset: The offset for pagination.
|
|
945
|
-
:param statuses: The statuses of the runs to be listed.
|
|
946
|
-
:param additional_metadata: Additional metadata for filtering the runs.
|
|
947
|
-
:param worker_id: The ID of the worker that ran the tasks.
|
|
948
|
-
:param parent_task_external_id: The external ID of the parent task.
|
|
949
|
-
:param only_tasks: Whether to list only task runs.
|
|
950
|
-
:param triggering_event_external_id: The event id that triggered the task run.
|
|
1127
|
+
:param input: The input data for the workflow.
|
|
1128
|
+
:param options: Additional options for workflow execution.
|
|
951
1129
|
|
|
952
|
-
:returns: A
|
|
1130
|
+
:returns: A `WorkflowRunRef` object representing the reference to the workflow run.
|
|
953
1131
|
"""
|
|
954
|
-
|
|
1132
|
+
return self._extract_result(self._workflow.run(input, options))
|
|
955
1133
|
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1134
|
+
async def aio_run(
|
|
1135
|
+
self,
|
|
1136
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
1137
|
+
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
1138
|
+
) -> R:
|
|
1139
|
+
"""
|
|
1140
|
+
Run the workflow asynchronously and wait for it to complete.
|
|
959
1141
|
|
|
960
|
-
workflow
|
|
1142
|
+
This method triggers a workflow run, blocks until completion, and returns the final result.
|
|
961
1143
|
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
since=since or datetime.now() - timedelta(days=1),
|
|
965
|
-
only_tasks=only_tasks,
|
|
966
|
-
offset=offset,
|
|
967
|
-
limit=limit,
|
|
968
|
-
statuses=statuses,
|
|
969
|
-
until=until,
|
|
970
|
-
additional_metadata=additional_metadata,
|
|
971
|
-
worker_id=worker_id,
|
|
972
|
-
parent_task_external_id=parent_task_external_id,
|
|
973
|
-
triggering_event_external_id=triggering_event_external_id,
|
|
974
|
-
)
|
|
1144
|
+
:param input: The input data for the workflow, must match the workflow's input type.
|
|
1145
|
+
:param options: Additional options for workflow execution like metadata and parent workflow ID.
|
|
975
1146
|
|
|
976
|
-
|
|
1147
|
+
:returns: The result of the workflow execution as a dictionary.
|
|
1148
|
+
"""
|
|
1149
|
+
result = await self._workflow.aio_run(input, options)
|
|
1150
|
+
return self._extract_result(result)
|
|
977
1151
|
|
|
978
|
-
|
|
1152
|
+
def run_no_wait(
|
|
979
1153
|
self,
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
offset: int | None = None,
|
|
984
|
-
statuses: list[V1TaskStatus] | None = None,
|
|
985
|
-
additional_metadata: dict[str, str] | None = None,
|
|
986
|
-
worker_id: str | None = None,
|
|
987
|
-
parent_task_external_id: str | None = None,
|
|
988
|
-
only_tasks: bool = False,
|
|
989
|
-
triggering_event_external_id: str | None = None,
|
|
990
|
-
) -> list[V1TaskSummary]:
|
|
1154
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
1155
|
+
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
1156
|
+
) -> TaskRunRef[TWorkflowInput, R]:
|
|
991
1157
|
"""
|
|
992
|
-
|
|
1158
|
+
Run the workflow synchronously and wait for it to complete.
|
|
993
1159
|
|
|
994
|
-
|
|
995
|
-
:param until: The end time for the runs to be listed.
|
|
996
|
-
:param limit: The maximum number of runs to be listed.
|
|
997
|
-
:param offset: The offset for pagination.
|
|
998
|
-
:param statuses: The statuses of the runs to be listed.
|
|
999
|
-
:param additional_metadata: Additional metadata for filtering the runs.
|
|
1000
|
-
:param worker_id: The ID of the worker that ran the tasks.
|
|
1001
|
-
:param parent_task_external_id: The external ID of the parent task.
|
|
1002
|
-
:param only_tasks: Whether to list only task runs.
|
|
1003
|
-
:param triggering_event_external_id: The event id that triggered the task run.
|
|
1160
|
+
This method triggers a workflow run, blocks until completion, and returns the final result.
|
|
1004
1161
|
|
|
1005
|
-
:
|
|
1162
|
+
:param input: The input data for the workflow, must match the workflow's input type.
|
|
1163
|
+
:param options: Additional options for workflow execution like metadata and parent workflow ID.
|
|
1164
|
+
|
|
1165
|
+
:returns: The result of the workflow execution as a dictionary.
|
|
1006
1166
|
"""
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1167
|
+
ref = self._workflow.run_no_wait(input, options)
|
|
1168
|
+
|
|
1169
|
+
return TaskRunRef[TWorkflowInput, R](self, ref)
|
|
1170
|
+
|
|
1171
|
+
async def aio_run_no_wait(
|
|
1172
|
+
self,
|
|
1173
|
+
input: TWorkflowInput = cast(TWorkflowInput, EmptyModel()),
|
|
1174
|
+
options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
|
|
1175
|
+
) -> TaskRunRef[TWorkflowInput, R]:
|
|
1176
|
+
"""
|
|
1177
|
+
Asynchronously trigger a workflow run without waiting for it to complete.
|
|
1178
|
+
This method is useful for starting a workflow run and immediately returning a reference to the run without blocking while the workflow runs.
|
|
1179
|
+
|
|
1180
|
+
:param input: The input data for the workflow.
|
|
1181
|
+
:param options: Additional options for workflow execution.
|
|
1182
|
+
|
|
1183
|
+
:returns: A `WorkflowRunRef` object representing the reference to the workflow run.
|
|
1184
|
+
"""
|
|
1185
|
+
ref = await self._workflow.aio_run_no_wait(input, options)
|
|
1186
|
+
|
|
1187
|
+
return TaskRunRef[TWorkflowInput, R](self, ref)
|
|
1188
|
+
|
|
1189
|
+
def run_many(self, workflows: list[WorkflowRunTriggerConfig]) -> list[R]:
|
|
1190
|
+
"""
|
|
1191
|
+
Run a workflow in bulk and wait for all runs to complete.
|
|
1192
|
+
This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.
|
|
1193
|
+
|
|
1194
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
1195
|
+
:returns: A list of results for each workflow run.
|
|
1196
|
+
"""
|
|
1197
|
+
return [
|
|
1198
|
+
self._extract_result(result)
|
|
1199
|
+
for result in self._workflow.run_many(workflows)
|
|
1200
|
+
]
|
|
1201
|
+
|
|
1202
|
+
async def aio_run_many(self, workflows: list[WorkflowRunTriggerConfig]) -> list[R]:
|
|
1203
|
+
"""
|
|
1204
|
+
Run a workflow in bulk and wait for all runs to complete.
|
|
1205
|
+
This method triggers multiple workflow runs, blocks until all of them complete, and returns the final results.
|
|
1206
|
+
|
|
1207
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
1208
|
+
:returns: A list of results for each workflow run.
|
|
1209
|
+
"""
|
|
1210
|
+
return [
|
|
1211
|
+
self._extract_result(result)
|
|
1212
|
+
for result in await self._workflow.aio_run_many(workflows)
|
|
1213
|
+
]
|
|
1214
|
+
|
|
1215
|
+
def run_many_no_wait(
|
|
1216
|
+
self, workflows: list[WorkflowRunTriggerConfig]
|
|
1217
|
+
) -> list[TaskRunRef[TWorkflowInput, R]]:
|
|
1218
|
+
"""
|
|
1219
|
+
Run a workflow in bulk without waiting for all runs to complete.
|
|
1220
|
+
|
|
1221
|
+
This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.
|
|
1222
|
+
|
|
1223
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
1224
|
+
:returns: A list of `WorkflowRunRef` objects, each representing a reference to a workflow run.
|
|
1225
|
+
"""
|
|
1226
|
+
refs = self._workflow.run_many_no_wait(workflows)
|
|
1227
|
+
|
|
1228
|
+
return [TaskRunRef[TWorkflowInput, R](self, ref) for ref in refs]
|
|
1229
|
+
|
|
1230
|
+
async def aio_run_many_no_wait(
|
|
1231
|
+
self, workflows: list[WorkflowRunTriggerConfig]
|
|
1232
|
+
) -> list[TaskRunRef[TWorkflowInput, R]]:
|
|
1233
|
+
"""
|
|
1234
|
+
Run a workflow in bulk without waiting for all runs to complete.
|
|
1235
|
+
|
|
1236
|
+
This method triggers multiple workflow runs and immediately returns a list of references to the runs without blocking while the workflows run.
|
|
1237
|
+
|
|
1238
|
+
:param workflows: A list of `WorkflowRunTriggerConfig` objects, each representing a workflow run to be triggered.
|
|
1239
|
+
|
|
1240
|
+
:returns: A list of `WorkflowRunRef` objects, each representing a reference to a workflow run.
|
|
1241
|
+
"""
|
|
1242
|
+
refs = await self._workflow.aio_run_many_no_wait(workflows)
|
|
1243
|
+
|
|
1244
|
+
return [TaskRunRef[TWorkflowInput, R](self, ref) for ref in refs]
|