Skip to content

Commit c165371

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

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

openhexa/sdk/client/__init__.py

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

33
from ..utils import OpenHexaClient
44

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

7+
def get_openhexa():
8+
global _openhexa
9+
if _openhexa is None:
10+
_openhexa = OpenHexaClient()
11+
return _openhexa
712

8-
__all__ = ["openhexa"]
13+
__all__ = ["get_openhexa"]

openhexa/sdk/pipelines/run.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import os
66
from typing import Any
77

8-
from openhexa.graphql import CurrentPipelineRunCurrentPipelineRunPipeline
9-
from openhexa.sdk.client import OpenHexaClient
8+
109
from openhexa.sdk.pipelines.log_level import LogLevel
1110
from openhexa.sdk.utils import Environment, get_environment, graphql
1211
from openhexa.sdk.workspaces import workspace
1312

13+
from openhexa.sdk.client import get_openhexa
14+
15+
from openhexa.graphql import CurrentPipelineRunCurrentPipelineRunPipeline
16+
1417

1518
class CurrentRun:
1619
"""Represents the current run of a pipeline.
@@ -27,18 +30,18 @@ def _connected(self):
2730
def pipeline_run_id(self) -> Any:
2831
"""Get the current pipeline run ID."""
2932
if self._connected:
30-
# Use the OpenHexaClient to get the current pipeline run ID
31-
return OpenHexaClient().current_pipeline_run()["id"]
33+
return get_openhexa().current_pipeline_run()["id"]
3234
else:
3335
raise RuntimeError(
3436
"CurrentRun is not connected to the OpenHEXA server. "
3537
"Make sure to set the HEXA_SERVER_URL environment variable."
3638
)
3739

40+
3841
def get_pipline(self) -> CurrentPipelineRunCurrentPipelineRunPipeline:
3942
"""Get the current pipeline."""
4043
if self._connected:
41-
return OpenHexaClient().current_pipeline_run()["pipeline"]
44+
return get_openhexa().current_pipeline_run()["pipeline"]
4245
else:
4346
raise RuntimeError(
4447
"CurrentRun is not connected to the OpenHEXA server. "

0 commit comments

Comments
 (0)