about summary refs log tree commit diff
path: root/.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py
diff options
context:
space:
mode:
authorS. Solomon Darnell2025-03-28 21:52:21 -0500
committerS. Solomon Darnell2025-03-28 21:52:21 -0500
commit4a52a71956a8d46fcb7294ac71734504bb09bcc2 (patch)
treeee3dc5af3b6313e921cd920906356f5d4febc4ed /.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py
parentcc961e04ba734dd72309fb548a2f97d67d578813 (diff)
downloadgn-ai-master.tar.gz
two version of R2R are here HEAD master
Diffstat (limited to '.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py')
-rw-r--r--.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py b/.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py
new file mode 100644
index 00000000..73d9e3b4
--- /dev/null
+++ b/.venv/lib/python3.12/site-packages/hatchet_sdk/v2/concurrency.py
@@ -0,0 +1,47 @@
+from typing import Any, Callable
+
+from hatchet_sdk.context.context import Context
+from hatchet_sdk.contracts.workflows_pb2 import (  # type: ignore[attr-defined]
+    ConcurrencyLimitStrategy,
+)
+
+
+class ConcurrencyFunction:
+    def __init__(
+        self,
+        func: Callable[[Context], str],
+        name: str = "concurrency",
+        max_runs: int = 1,
+        limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
+    ):
+        self.func = func
+        self.name = name
+        self.max_runs = max_runs
+        self.limit_strategy = limit_strategy
+        self.namespace = "default"
+
+    def set_namespace(self, namespace: str) -> None:
+        self.namespace = namespace
+
+    def get_action_name(self) -> str:
+        return self.namespace + ":" + self.name
+
+    def __call__(self, *args: Any, **kwargs: Any) -> str:
+        return self.func(*args, **kwargs)
+
+    def __str__(self) -> str:
+        return f"{self.name}({self.max_runs})"
+
+    def __repr__(self) -> str:
+        return f"{self.name}({self.max_runs})"
+
+
+def concurrency(
+    name: str = "",
+    max_runs: int = 1,
+    limit_strategy: ConcurrencyLimitStrategy = ConcurrencyLimitStrategy.GROUP_ROUND_ROBIN,
+) -> Callable[[Callable[[Context], str]], ConcurrencyFunction]:
+    def inner(func: Callable[[Context], str]) -> ConcurrencyFunction:
+        return ConcurrencyFunction(func, name, max_runs, limit_strategy)
+
+    return inner