continuum-task-server-sdk 1.6.0__tar.gz → 1.7.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: continuum-task-server-sdk
3
- Version: 1.6.0
3
+ Version: 1.7.0
4
4
  Summary: Python SDK for the Continuum Task Server
5
5
  Project-URL: Homepage, https://github.com/ContinuumWorkflow/continuum-task-server-sdk-python
6
6
  Project-URL: Issues, https://github.com/ContinuumWorkflow/continuum-task-server-sdk-python/issues
@@ -77,4 +77,4 @@ __all__ = [
77
77
  "WorkSubscriptionResult",
78
78
  ]
79
79
 
80
- __version__ = "1.6.0"
80
+ __version__ = "1.6.2"
@@ -11,7 +11,7 @@ from uuid import UUID
11
11
  import httpx
12
12
 
13
13
  from ._http import HttpClient, drop_none
14
- from .exceptions import ContinuumError
14
+ from .exceptions import ContinuumError, error_for_status
15
15
  from .models import (
16
16
  Content,
17
17
  QueueDescendantsCancelResult,
@@ -23,6 +23,21 @@ from .models import (
23
23
  )
24
24
 
25
25
 
26
+ def _id_from(body: Any, object_name: str, missing_message: str, bad_id_message: str) -> UUID:
27
+ if isinstance(body, dict) and body.get("status") not in (None, 0):
28
+ status = int(body["status"])
29
+ message = body.get("message")
30
+ raise error_for_status(status, "" if message is None else str(message))
31
+ node = body.get(object_name) if isinstance(body, dict) else None
32
+ raw = node.get("id") if isinstance(node, dict) else None
33
+ if raw is None or raw == "":
34
+ raise ContinuumError(missing_message)
35
+ try:
36
+ return UUID(str(raw))
37
+ except ValueError as ex:
38
+ raise ContinuumError(bad_id_message) from ex
39
+
40
+
26
41
  def _encode_input(data: Any) -> str | None:
27
42
  """Accept dict/list/str/None and return a JSON string (or None)."""
28
43
  if data is None:
@@ -242,8 +257,13 @@ class QueueApi:
242
257
  idempotency_token: str | None = None,
243
258
  layer: str | None = None,
244
259
  strict_layer: bool | None = None,
260
+ actor_event_id: UUID | str | None = None,
245
261
  ) -> QueueItem:
246
- """Add a queue item. At least one of task_name or task_item_name is required."""
262
+ """Add a queue item. At least one of task_name or task_item_name is required.
263
+
264
+ ``actor_event_id`` is the actor event that started this child. It is omitted
265
+ for an ordinary enqueue.
266
+ """
247
267
  if task_name is None and task_item_name is None:
248
268
  raise ValueError("at least one of task_name or task_item_name is required")
249
269
  body = drop_none(
@@ -256,6 +276,7 @@ class QueueApi:
256
276
  "idempotencyToken": idempotency_token,
257
277
  "layer": layer,
258
278
  "strictLayer": strict_layer,
279
+ "actorEventId": str(actor_event_id) if actor_event_id else None,
259
280
  }
260
281
  )
261
282
  return QueueItem.model_validate(self._http.post_json(self._MGMT, body))
@@ -418,6 +439,60 @@ class ContinuumClient:
418
439
  """Attach the secret from task-server registration. Blank clears it."""
419
440
  self._http.set_task_server_token(token)
420
441
 
442
+ def register_data_subscription(
443
+ self,
444
+ layer: str | None = None,
445
+ strict_layer: bool | None = None,
446
+ subject: str | None = None,
447
+ filter: Any = None,
448
+ delivery_kind: str | None = None,
449
+ actor_instance_id: UUID | str | None = None,
450
+ task_item_id: UUID | str | None = None,
451
+ ) -> UUID:
452
+ """POST /api/data-subscriptions. None arguments are omitted. False is sent."""
453
+ body = drop_none(
454
+ {
455
+ "layer": layer,
456
+ "strictLayer": strict_layer,
457
+ "subject": subject,
458
+ "filter": filter,
459
+ "deliveryKind": delivery_kind,
460
+ "actorInstanceId": None if actor_instance_id is None else str(actor_instance_id),
461
+ "taskItemId": None if task_item_id is None else str(task_item_id),
462
+ }
463
+ )
464
+ return _id_from(
465
+ self._http.post_json("/api/data-subscriptions", body),
466
+ "subscription",
467
+ "registerDataSubscription succeeded without a subscription id",
468
+ "registerDataSubscription subscription id is not a UUID",
469
+ )
470
+
471
+ def insert_ingress_event(
472
+ self,
473
+ task_server_id: UUID | str | None = None,
474
+ source: str | None = None,
475
+ source_message_id: str | None = None,
476
+ address: Any = None,
477
+ payload: Any = None,
478
+ ) -> UUID:
479
+ """POST /api/ingress-events. None arguments are omitted."""
480
+ body = drop_none(
481
+ {
482
+ "taskServerId": None if task_server_id is None else str(task_server_id),
483
+ "source": source,
484
+ "sourceMessageId": source_message_id,
485
+ "address": address,
486
+ "payload": payload,
487
+ }
488
+ )
489
+ return _id_from(
490
+ self._http.post_json("/api/ingress-events", body),
491
+ "event",
492
+ "insertIngressEvent succeeded without an ingress event id",
493
+ "insertIngressEvent event id is not a UUID",
494
+ )
495
+
421
496
  def post_raw(self, path: str, body: Any) -> Any:
422
497
  return self._http.post_json(path, body)
423
498
 
@@ -39,6 +39,20 @@ from .models import (
39
39
 
40
40
  logger = logging.getLogger("continuum_task_server")
41
41
 
42
+
43
+ def _reply_id(
44
+ body: dict[str, Any], object_name: str, missing_message: str, bad_id_message: str
45
+ ) -> UUID:
46
+ node = body.get(object_name) if isinstance(body, dict) else None
47
+ raw = node.get("id") if isinstance(node, dict) else None
48
+ if raw is None or raw == "":
49
+ raise ContinuumError(missing_message)
50
+ try:
51
+ return UUID(str(raw))
52
+ except ValueError as ex:
53
+ raise ContinuumError(bad_id_message) from ex
54
+
55
+
42
56
  Connector = Callable[[str, dict[str, str], float], "SocketLike"]
43
57
  EventCallback = Callable[[QueueEvent], None]
44
58
 
@@ -231,6 +245,7 @@ class ContinuumWebSocketClient:
231
245
  idempotency_token: str | None = None,
232
246
  layer: str | None = None,
233
247
  strict_layer: bool | None = None,
248
+ actor_event_id: UUID | str | None = None,
234
249
  ) -> QueueItem:
235
250
  if task_name is None and task_item_name is None:
236
251
  raise ValueError("at least one of task_name or task_item_name is required")
@@ -244,6 +259,7 @@ class ContinuumWebSocketClient:
244
259
  "idempotencyToken": idempotency_token,
245
260
  "layer": layer,
246
261
  "strictLayer": strict_layer,
262
+ "actorEventId": str(actor_event_id) if actor_event_id else None,
247
263
  }
248
264
  )
249
265
  payload = self._command("/app/enqueue", body, request_id=request_id, retry=False)
@@ -267,6 +283,7 @@ class ContinuumWebSocketClient:
267
283
  idempotency_token: str | None = None,
268
284
  layer: str | None = None,
269
285
  strict_layer: bool | None = None,
286
+ actor_event_id: UUID | str | None = None,
270
287
  ) -> EnqueueAndSubscribeWaitResult:
271
288
  if task_name is None and task_item_name is None:
272
289
  raise ValueError("at least one of task_name or task_item_name is required")
@@ -286,6 +303,7 @@ class ContinuumWebSocketClient:
286
303
  "idempotencyToken": idempotency_token,
287
304
  "layer": layer,
288
305
  "strictLayer": strict_layer,
306
+ "actorEventId": str(actor_event_id) if actor_event_id else None,
289
307
  }
290
308
  )
291
309
  payload = self._command(
@@ -501,6 +519,76 @@ class ContinuumWebSocketClient:
501
519
  )
502
520
  return EventAckResult.model_validate(payload)
503
521
 
522
+ def register_data_subscription(
523
+ self,
524
+ layer: str | None = None,
525
+ strict_layer: bool | None = None,
526
+ subject: str | None = None,
527
+ filter: Any = None,
528
+ delivery_kind: str | None = None,
529
+ actor_instance_id: UUID | str | None = None,
530
+ task_item_id: UUID | str | None = None,
531
+ *,
532
+ request_id: str | None = None,
533
+ ) -> UUID:
534
+ """Send /app/registerDataSubscription. None arguments are omitted. False is sent."""
535
+ body = drop_none(
536
+ {
537
+ "layer": layer,
538
+ "strictLayer": strict_layer,
539
+ "subject": subject,
540
+ "filter": filter,
541
+ "deliveryKind": delivery_kind,
542
+ "actorInstanceId": None if actor_instance_id is None else str(actor_instance_id),
543
+ "taskItemId": None if task_item_id is None else str(task_item_id),
544
+ }
545
+ )
546
+ payload = self._command(
547
+ "/app/registerDataSubscription",
548
+ body,
549
+ request_id=request_id,
550
+ retry=False,
551
+ )
552
+ return _reply_id(
553
+ payload,
554
+ "subscription",
555
+ "registerDataSubscription succeeded without a subscription id",
556
+ "registerDataSubscription subscription id is not a UUID",
557
+ )
558
+
559
+ def insert_ingress_event(
560
+ self,
561
+ task_server_id: UUID | str | None = None,
562
+ source: str | None = None,
563
+ source_message_id: str | None = None,
564
+ address: Any = None,
565
+ payload: Any = None,
566
+ *,
567
+ request_id: str | None = None,
568
+ ) -> UUID:
569
+ """Send /app/insertIngressEvent. None arguments are omitted."""
570
+ body = drop_none(
571
+ {
572
+ "taskServerId": None if task_server_id is None else str(task_server_id),
573
+ "source": source,
574
+ "sourceMessageId": source_message_id,
575
+ "address": address,
576
+ "payload": payload,
577
+ }
578
+ )
579
+ reply = self._command(
580
+ "/app/insertIngressEvent",
581
+ body,
582
+ request_id=request_id,
583
+ retry=False,
584
+ )
585
+ return _reply_id(
586
+ reply,
587
+ "event",
588
+ "insertIngressEvent succeeded without an ingress event id",
589
+ "insertIngressEvent event id is not a UUID",
590
+ )
591
+
504
592
  def _command(
505
593
  self,
506
594
  destination: str,
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "continuum-task-server-sdk"
7
- version = "1.6.0"
7
+ version = "1.7.0"
8
8
  description = "Python SDK for the Continuum Task Server"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"