Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose namespace option override #179

Merged
merged 4 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/dag/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

hatchet = Hatchet(debug=True)

for i in range(10):
hatchet.event.push("dag:create", {"test": "test"})
# for i in range(10):
hatchet.event.push("dag:create", {"test": "test"})
33 changes: 23 additions & 10 deletions hatchet_sdk/clients/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ class ChildTriggerWorkflowOptions(TypedDict):
class TriggerWorkflowOptions(ScheduleTriggerWorkflowOptions, TypedDict):
additional_metadata: Dict[str, str] | None = None
desired_worker_id: str | None = None


class TriggerWorkflowOptions(ScheduleTriggerWorkflowOptions, TypedDict):
additional_metadata: Dict[str, str] | None = None
desired_worker_id: str | None = None
namespace: str | None = None


class DedupeViolationErr(Exception):
Expand Down Expand Up @@ -177,9 +173,17 @@ async def run_workflow(
if not self.pooled_workflow_listener:
self.pooled_workflow_listener = PooledWorkflowRunListener(self.config)

# if workflow_name does not start with namespace, prepend it
if self.namespace != "" and not workflow_name.startswith(self.namespace):
workflow_name = f"{self.namespace}{workflow_name}"
namespace = self.namespace

if (
options is not None
and "namespace" in options
and options["namespace"] is not None
):
namespace = options["namespace"]

if namespace != "" and not workflow_name.startswith(self.namespace):
workflow_name = f"{namespace}{workflow_name}"

request = self._prepare_workflow_request(workflow_name, input, options)
resp: TriggerWorkflowResponse = await self.aio_client.TriggerWorkflow(
Expand Down Expand Up @@ -336,8 +340,17 @@ def run_workflow(
if not self.pooled_workflow_listener:
self.pooled_workflow_listener = PooledWorkflowRunListener(self.config)

if self.namespace != "" and not workflow_name.startswith(self.namespace):
workflow_name = f"{self.namespace}{workflow_name}"
namespace = self.namespace

if (
options is not None
and "namespace" in options
and options["namespace"] is not None
):
namespace = options["namespace"]

if namespace != "" and not workflow_name.startswith(self.namespace):
workflow_name = f"{namespace}{workflow_name}"

request = self._prepare_workflow_request(workflow_name, input, options)
resp: TriggerWorkflowResponse = self.client.TriggerWorkflow(
Expand Down
12 changes: 11 additions & 1 deletion hatchet_sdk/clients/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def proto_timestamp_now():

class PushEventOptions(TypedDict):
additional_metadata: Dict[str, str] | None = None
namespace: str | None = None


class EventClient:
Expand All @@ -46,7 +47,16 @@ def __init__(self, client: EventsServiceStub, config: ClientConfig):
@tenacity_retry
def push(self, event_key, payload, options: PushEventOptions = None) -> Event:

namespaced_event_key = self.namespace + event_key
namespace = self.namespace

if (
options is not None
and "namespace" in options
and options["namespace"] is not None
):
namespace = options["namespace"]

namespaced_event_key = namespace + event_key

try:
meta = None if options is None else options["additional_metadata"]
Expand Down
6 changes: 4 additions & 2 deletions hatchet_sdk/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ def get_config_value(key, env_var):
server_url: str | None = None

grpc_max_recv_message_length = get_config_value(
"grpc_max_recv_message_length", "HATCHET_CLIENT_GRPC_MAX_RECV_MESSAGE_LENGTH"
"grpc_max_recv_message_length",
"HATCHET_CLIENT_GRPC_MAX_RECV_MESSAGE_LENGTH",
)
grpc_max_send_message_length = get_config_value(
"grpc_max_send_message_length", "HATCHET_CLIENT_GRPC_MAX_SEND_MESSAGE_LENGTH"
"grpc_max_send_message_length",
"HATCHET_CLIENT_GRPC_MAX_SEND_MESSAGE_LENGTH",
)

if not host_port:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "hatchet-sdk"
version = "0.36.17"
version = "0.36.18"
description = ""
authors = ["Alexander Belanger <[email protected]>"]
readme = "README.md"
Expand Down
Loading