hatchet-sdk 1.2.3__py3-none-any.whl → 1.2.5__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.

@@ -1,7 +1,7 @@
1
1
  import asyncio
2
2
  import json
3
3
  from datetime import datetime
4
- from typing import Union, cast
4
+ from typing import Generator, TypeVar, Union, cast
5
5
 
6
6
  import grpc
7
7
  from google.protobuf import timestamp_pb2
@@ -27,6 +27,10 @@ from hatchet_sdk.utils.proto_enums import convert_python_enum_to_proto
27
27
  from hatchet_sdk.utils.typing import JSONSerializableMapping
28
28
  from hatchet_sdk.workflow_run import WorkflowRunRef
29
29
 
30
+ T = TypeVar("T")
31
+
32
+ MAX_BULK_WORKFLOW_RUN_BATCH_SIZE = 1000
33
+
30
34
 
31
35
  class ScheduleTriggerWorkflowOptions(BaseModel):
32
36
  parent_id: str | None = None
@@ -328,9 +332,6 @@ class AdminClient:
328
332
  input: JSONSerializableMapping,
329
333
  options: TriggerWorkflowOptions = TriggerWorkflowOptions(),
330
334
  ) -> WorkflowRunRef:
331
- ## IMPORTANT: The `pooled_workflow_listener` must be created 1) lazily, and not at `init` time, and 2) on the
332
- ## main thread. If 1) is not followed, you'll get an error about something being attached to the wrong event
333
- ## loop. If 2) is not followed, you'll get an error about the event loop not being set up.
334
335
  async with spawn_index_lock:
335
336
  request = self._create_workflow_run_request(workflow_name, input, options)
336
337
 
@@ -353,70 +354,90 @@ class AdminClient:
353
354
  config=self.config,
354
355
  )
355
356
 
357
+ def chunk(self, xs: list[T], n: int) -> Generator[list[T], None, None]:
358
+ for i in range(0, len(xs), n):
359
+ yield xs[i : i + n]
360
+
356
361
  ## IMPORTANT: Keep this method's signature in sync with the wrapper in the OTel instrumentor
357
362
  @tenacity_retry
358
363
  def run_workflows(
359
364
  self,
360
365
  workflows: list[WorkflowRunTriggerConfig],
361
366
  ) -> list[WorkflowRunRef]:
362
- bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
363
- workflows=[
364
- self._create_workflow_run_request(
365
- workflow.workflow_name, workflow.input, workflow.options
366
- )
367
- for workflow in workflows
368
- ]
369
- )
367
+ bulk_workflows = [
368
+ self._create_workflow_run_request(
369
+ workflow.workflow_name, workflow.input, workflow.options
370
+ )
371
+ for workflow in workflows
372
+ ]
370
373
 
371
- resp = cast(
372
- v0_workflow_protos.BulkTriggerWorkflowResponse,
373
- self.v0_client.BulkTriggerWorkflow(
374
- bulk_request,
375
- metadata=get_metadata(self.token),
376
- ),
377
- )
374
+ refs: list[WorkflowRunRef] = []
378
375
 
379
- return [
380
- WorkflowRunRef(
381
- workflow_run_id=workflow_run_id,
382
- config=self.config,
376
+ for chunk in self.chunk(bulk_workflows, MAX_BULK_WORKFLOW_RUN_BATCH_SIZE):
377
+ bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
378
+ workflows=chunk
383
379
  )
384
- for workflow_run_id in resp.workflow_run_ids
385
- ]
380
+
381
+ resp = cast(
382
+ v0_workflow_protos.BulkTriggerWorkflowResponse,
383
+ self.v0_client.BulkTriggerWorkflow(
384
+ bulk_request,
385
+ metadata=get_metadata(self.token),
386
+ ),
387
+ )
388
+
389
+ refs.extend(
390
+ [
391
+ WorkflowRunRef(
392
+ workflow_run_id=workflow_run_id,
393
+ config=self.config,
394
+ )
395
+ for workflow_run_id in resp.workflow_run_ids
396
+ ]
397
+ )
398
+
399
+ return refs
386
400
 
387
401
  @tenacity_retry
388
402
  async def aio_run_workflows(
389
403
  self,
390
404
  workflows: list[WorkflowRunTriggerConfig],
391
405
  ) -> list[WorkflowRunRef]:
392
- ## IMPORTANT: The `pooled_workflow_listener` must be created 1) lazily, and not at `init` time, and 2) on the
393
- ## main thread. If 1) is not followed, you'll get an error about something being attached to the wrong event
394
- ## loop. If 2) is not followed, you'll get an error about the event loop not being set up.
395
- async with spawn_index_lock:
396
- bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
397
- workflows=[
406
+ chunks = self.chunk(workflows, MAX_BULK_WORKFLOW_RUN_BATCH_SIZE)
407
+ refs: list[WorkflowRunRef] = []
408
+
409
+ for chunk in chunks:
410
+ async with spawn_index_lock:
411
+ bulk_workflows = [
398
412
  self._create_workflow_run_request(
399
413
  workflow.workflow_name, workflow.input, workflow.options
400
414
  )
401
- for workflow in workflows
415
+ for workflow in chunk
402
416
  ]
417
+
418
+ bulk_request = v0_workflow_protos.BulkTriggerWorkflowRequest(
419
+ workflows=bulk_workflows
403
420
  )
404
421
 
405
- resp = cast(
406
- v0_workflow_protos.BulkTriggerWorkflowResponse,
407
- self.v0_client.BulkTriggerWorkflow(
408
- bulk_request,
409
- metadata=get_metadata(self.token),
410
- ),
411
- )
422
+ resp = cast(
423
+ v0_workflow_protos.BulkTriggerWorkflowResponse,
424
+ self.v0_client.BulkTriggerWorkflow(
425
+ bulk_request,
426
+ metadata=get_metadata(self.token),
427
+ ),
428
+ )
412
429
 
413
- return [
414
- WorkflowRunRef(
415
- workflow_run_id=workflow_run_id,
416
- config=self.config,
430
+ refs.extend(
431
+ [
432
+ WorkflowRunRef(
433
+ workflow_run_id=workflow_run_id,
434
+ config=self.config,
435
+ )
436
+ for workflow_run_id in resp.workflow_run_ids
437
+ ]
417
438
  )
418
- for workflow_run_id in resp.workflow_run_ids
419
- ]
439
+
440
+ return refs
420
441
 
421
442
  def get_workflow_run(self, workflow_run_id: str) -> WorkflowRunRef:
422
443
  return WorkflowRunRef(
@@ -21,6 +21,7 @@ from hatchet_sdk.clients.v1.api_client import (
21
21
  )
22
22
  from hatchet_sdk.utils.aio import run_async_from_sync
23
23
  from hatchet_sdk.utils.typing import JSONSerializableMapping
24
+ from hatchet_sdk.workflow_run import WorkflowRunRef
24
25
 
25
26
 
26
27
  class RunFilter(BaseModel):
@@ -220,3 +221,9 @@ class RunsClient(BaseRestClient):
220
221
  details = self.get(run_id)
221
222
 
222
223
  return details.run.output
224
+
225
+ def get_run_ref(self, workflow_run_id: str) -> WorkflowRunRef:
226
+ return WorkflowRunRef(
227
+ workflow_run_id=workflow_run_id,
228
+ config=self.client_config,
229
+ )
@@ -25,6 +25,11 @@ class TaskRunRef(Generic[TWorkflowInput, R]):
25
25
  self._s = standalone
26
26
  self._wrr = workflow_run_ref
27
27
 
28
+ self.workflow_run_id = workflow_run_ref.workflow_run_id
29
+
30
+ def __str__(self) -> str:
31
+ return self.workflow_run_id
32
+
28
33
  async def aio_result(self) -> R:
29
34
  result = await self._wrr.workflow_listener.aio_result(self._wrr.workflow_run_id)
30
35
  return self._s._extract_result(result)
@@ -274,7 +274,7 @@ class BaseWorkflow(Generic[TWorkflowInput]):
274
274
 
275
275
  @property
276
276
  def name(self) -> str:
277
- return self.config.name
277
+ return self._get_name(self.client.config.namespace)
278
278
 
279
279
  def create_bulk_run_item(
280
280
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hatchet-sdk
3
- Version: 1.2.3
3
+ Version: 1.2.5
4
4
  Summary:
5
5
  Author: Alexander Belanger
6
6
  Author-email: alexander@hatchet.run
@@ -1,6 +1,6 @@
1
1
  hatchet_sdk/__init__.py,sha256=o_06wLLKCKRq4uQuCF62yDRb8hTQYYcqPC3FIDNHxuQ,10002
2
2
  hatchet_sdk/client.py,sha256=lApcV1-qlvIdiHyGrQJAIlT9qzP96I0mQ2STZ1ZV_2g,1940
3
- hatchet_sdk/clients/admin.py,sha256=cc-TyZL6uLz3MGpdVKYziiZlmi29twP8MUJ66CboLtU,15160
3
+ hatchet_sdk/clients/admin.py,sha256=1pY3RlJmVjFAfxX6kwVMd7jO_JHxkei6jrz8XUJUaKI,15333
4
4
  hatchet_sdk/clients/dispatcher/action_listener.py,sha256=FogjHd6vhj4HeQs--Z-99kPwCfaETo1-EcotjdIkrig,16266
5
5
  hatchet_sdk/clients/dispatcher/dispatcher.py,sha256=7tHEoCvL2MKklxbT43oRsQdx9JuLIVCJvFuIUqTHjis,7794
6
6
  hatchet_sdk/clients/durable_event_listener.py,sha256=J5Tg8niikms-tEfB8wps_wgsPF7Fx-pYhYExd0lJo7Y,11791
@@ -245,7 +245,7 @@ hatchet_sdk/features/cron.py,sha256=VRq5w15QpVYMkvkyIUgBO77IQpASbTxyplbgGukdmE8,
245
245
  hatchet_sdk/features/logs.py,sha256=Fm3l0f2VUlQ_YqYrKqHYviK5g_j9_wUEW6J_Ax9cYzc,724
246
246
  hatchet_sdk/features/metrics.py,sha256=Lmmu-3TITHyGGx5moA_emuzy-ZrbJhXLBDzR7Fm73pk,2897
247
247
  hatchet_sdk/features/rate_limits.py,sha256=Df-DBFRpT1MHRf7qcvD4YJseNuFJUp5X9aO72yLkW6Q,1521
248
- hatchet_sdk/features/runs.py,sha256=th2czurM9uawOlcm48MBalvQTqSmfVhOMcAbHjPH_hk,8145
248
+ hatchet_sdk/features/runs.py,sha256=0r1sRWgsmKxDGR96-u5uT1mZ66ZKuX99X1F9uOb178I,8390
249
249
  hatchet_sdk/features/scheduled.py,sha256=MfUrUOYNWewoX6GJ4YV2UWmKrxVJrgj4fX8wCxkkgv0,8900
250
250
  hatchet_sdk/features/workers.py,sha256=HpUX8LyvFfseNn677tTvQukNqyD90-uWPhdf10znUkA,1589
251
251
  hatchet_sdk/features/workflows.py,sha256=4hZgk7vhRhMK8wb2K3b9617TolnxRkeYL35aeLWHY2c,2143
@@ -257,10 +257,10 @@ hatchet_sdk/opentelemetry/instrumentor.py,sha256=KYZG1koVv4704kgr7YJ-M3QqRcTrZI2
257
257
  hatchet_sdk/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
258
258
  hatchet_sdk/rate_limit.py,sha256=TwbCuggiZaWpYuo4mjVLlE-z1OfQ2mRBiVvCSaG3lv4,3919
259
259
  hatchet_sdk/runnables/contextvars.py,sha256=6MDocAMmlyiRW37oQ1jyx10tAlJs-xgDjR3xPoPz05g,426
260
- hatchet_sdk/runnables/standalone.py,sha256=2jgUgILYIyHSYy3S6M6n2QAQ7UyvxfSQk0DDRar5RpI,5996
260
+ hatchet_sdk/runnables/standalone.py,sha256=Qcg1oc7NlTw2ZCqq5D869fhssKBLUaZKUwDo4UVcVm4,6128
261
261
  hatchet_sdk/runnables/task.py,sha256=jQiRPeE9EbIzNOxv6hkmJ8RqyVR7hMLXX4cnGRl_GF8,4832
262
262
  hatchet_sdk/runnables/types.py,sha256=JWo4hkYb2XYoktIFVvnqud6Ywmo7AHMK_upYpdNmij0,4235
263
- hatchet_sdk/runnables/workflow.py,sha256=eYIbpAAwlArhEZrd3NHDT4Yy8_GejgCzRG6TZomPugI,30681
263
+ hatchet_sdk/runnables/workflow.py,sha256=8jfS4N9dHMteVKGmF1xbytYN82lN5rhIkleaQFGl6yI,30709
264
264
  hatchet_sdk/token.py,sha256=KjIiInwG5Kqd_FO4BSW1x_5Uc7PFbnzIVJqr50-ZldE,779
265
265
  hatchet_sdk/utils/aio.py,sha256=A9pKNn8eAKUeinY2uBkJn4jdrYI5vAw_A-gzz04xdvQ,1122
266
266
  hatchet_sdk/utils/backoff.py,sha256=6B5Rb5nLKw_TqqgpJMYjIBV1PTTtbOMRZCveisVhg_I,353
@@ -506,7 +506,7 @@ hatchet_sdk/worker/runner/runner.py,sha256=ZocvR7dDgEvSxcHAWDDaoTasSz3Wio70TbEbB
506
506
  hatchet_sdk/worker/runner/utils/capture_logs.py,sha256=nHRPSiDBqzhObM7i2X7t03OupVFnE7kQBdR2Ckgg-2w,2709
507
507
  hatchet_sdk/worker/worker.py,sha256=qyHs64H-grF9HR1CgH7MlnoDmTQ8mm4d8basx-ZDyWc,14490
508
508
  hatchet_sdk/workflow_run.py,sha256=Q1nTpnWNsFfjWWpx49xXYUHsVbqTnHL6JWnSKoFM3_I,1029
509
- hatchet_sdk-1.2.3.dist-info/METADATA,sha256=ix70mJ0CDQ0s-8MQRt_1KaVyCozNUXqFzd5iDspc7GE,3571
510
- hatchet_sdk-1.2.3.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
511
- hatchet_sdk-1.2.3.dist-info/entry_points.txt,sha256=5mTp_AsCWK5raiVxP_MU9eBCgkRGl4OsN6chpHcvm7o,1235
512
- hatchet_sdk-1.2.3.dist-info/RECORD,,
509
+ hatchet_sdk-1.2.5.dist-info/METADATA,sha256=AVLhMrxRJlLVaT9XkdJjPVIfpiyDdOpFMdn_Ak4Hxds,3571
510
+ hatchet_sdk-1.2.5.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
511
+ hatchet_sdk-1.2.5.dist-info/entry_points.txt,sha256=5mTp_AsCWK5raiVxP_MU9eBCgkRGl4OsN6chpHcvm7o,1235
512
+ hatchet_sdk-1.2.5.dist-info/RECORD,,