Skip to content

Commit 79c4382

Browse files
author
nazarfil
committed
fix: delay openehxa client instantiation
1 parent 926ac53 commit 79c4382

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

openhexa/sdk/client/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
from ..utils import OpenHexaClient
44

5-
openhexa = OpenHexaClient()
5+
_openhexa = None
66

77

8-
__all__ = ["openhexa"]
8+
def get_openhexa():
9+
"""Get the OpenHexa client instance."""
10+
global _openhexa
11+
if _openhexa is None:
12+
_openhexa = OpenHexaClient()
13+
return _openhexa
14+
15+
16+
__all__ = ["get_openhexa"]

openhexa/sdk/pipelines/run.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from typing import Any
77

88
from openhexa.graphql import CurrentPipelineRunCurrentPipelineRunPipeline
9-
from openhexa.sdk.client import OpenHexaClient
9+
from openhexa.sdk.client import get_openhexa
1010
from openhexa.sdk.pipelines.log_level import LogLevel
1111
from openhexa.sdk.utils import Environment, get_environment, graphql
1212
from openhexa.sdk.workspaces import workspace
@@ -27,8 +27,7 @@ def _connected(self):
2727
def pipeline_run_id(self) -> Any:
2828
"""Get the current pipeline run ID."""
2929
if self._connected:
30-
# Use the OpenHexaClient to get the current pipeline run ID
31-
return OpenHexaClient().current_pipeline_run()["id"]
30+
return get_openhexa().current_pipeline_run()["id"]
3231
else:
3332
raise RuntimeError(
3433
"CurrentRun is not connected to the OpenHEXA server. "
@@ -38,7 +37,7 @@ def pipeline_run_id(self) -> Any:
3837
def get_pipline(self) -> CurrentPipelineRunCurrentPipelineRunPipeline:
3938
"""Get the current pipeline."""
4039
if self._connected:
41-
return OpenHexaClient().current_pipeline_run()["pipeline"]
40+
return get_openhexa().current_pipeline_run()["pipeline"]
4241
else:
4342
raise RuntimeError(
4443
"CurrentRun is not connected to the OpenHEXA server. "

0 commit comments

Comments
 (0)