Skip to content

Commit 18e66be

Browse files
committed
Fix propagation of configuration to offline class and initialisation from parent class for Offline
1 parent 96f1178 commit 18e66be

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Fixed bug with `requirements.txt` metadata read.
66
* Added Simvue server version check.
77
* Remove checking of server version in offline mode and add default run mode to configuration options.
8+
* Fix offline mode class initialisation, and propagation of configuration.
89

910
## [v1.1.2](https://github.com/simvue-io/client/releases/tag/v1.1.2) - 2024-11-06
1011

simvue/factory/proxy/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ def Simvue(
2323
suppress_errors: bool = True,
2424
) -> "SimvueBaseClass":
2525
if mode == "offline":
26-
return Offline(name=name, uniq_id=uniq_id, suppress_errors=suppress_errors)
26+
return Offline(
27+
name=name, uniq_id=uniq_id, suppress_errors=suppress_errors, config=config
28+
)
2729
else:
2830
return Remote(
2931
name=name, uniq_id=uniq_id, config=config, suppress_errors=suppress_errors

simvue/factory/proxy/offline.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,15 @@ class Offline(SimvueBaseClass):
2828
"""
2929

3030
def __init__(
31-
self, name: typing.Optional[str], uniq_id: str, suppress_errors: bool = True
31+
self,
32+
name: typing.Optional[str],
33+
uniq_id: str,
34+
config: SimvueConfiguration,
35+
suppress_errors: bool = True,
3236
) -> None:
33-
super().__init__(name, uniq_id, suppress_errors)
37+
super().__init__(name=name, uniq_id=uniq_id, suppress_errors=suppress_errors)
3438

35-
_offline_dir = SimvueConfiguration.fetch().offline.cache
39+
_offline_dir = config.offline.cache
3640
self._directory: str = os.path.join(_offline_dir, self._uuid)
3741

3842
os.makedirs(self._directory, exist_ok=True)

simvue/run.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def check_run_initialised(
7474
) -> typing.Callable[..., typing.Any]:
7575
@functools.wraps(function)
7676
def _wrapper(self: Self, *args: typing.Any, **kwargs: typing.Any) -> typing.Any:
77-
if self._mode == "disabled":
77+
if self._user_config.run.mode == "disabled":
7878
return True
7979

8080
if self._retention and time.time() - self._timer > self._retention:
@@ -129,7 +129,6 @@ def __init__(
129129
run in debug mode, default is False
130130
"""
131131
self._uuid: str = f"{uuid.uuid4()}"
132-
self._mode: typing.Literal["online", "offline", "disabled"] = mode
133132
self._name: typing.Optional[str] = None
134133

135134
# monitor duration with respect to retention period
@@ -202,7 +201,9 @@ def _handle_exception_throw(
202201
)
203202
_is_running: bool = self._status == "running"
204203
_is_running_online: bool = self._id is not None and _is_running
205-
_is_running_offline: bool = self._mode == "offline" and _is_running
204+
_is_running_offline: bool = (
205+
self._user_config.run.mode == "offline" and _is_running
206+
)
206207
_is_terminated: bool = (
207208
_exception_thrown is not None and _exception_thrown == "KeyboardInterrupt"
208209
)
@@ -250,7 +251,7 @@ def __exit__(
250251
) -> None:
251252
logger.debug(
252253
"Automatically closing run '%s' in status %s",
253-
self._id if self._mode == "online" else "unregistered",
254+
self._id if self._user_config.run.mode == "online" else "unregistered",
254255
self._status,
255256
)
256257

@@ -315,7 +316,7 @@ def _create_heartbeat_callback(
315316
self,
316317
) -> typing.Callable[[threading.Event], None]:
317318
if (
318-
self._mode == "online"
319+
self._user_config.run.mode == "online"
319320
and (not self._user_config.server.url or not self._id)
320321
) or not self._heartbeat_termination_trigger:
321322
raise RuntimeError("Could not commence heartbeat, run not initialised")
@@ -395,7 +396,7 @@ def _create_dispatch_callback(
395396
executed on metrics and events objects held in a buffer.
396397
"""
397398

398-
if self._mode == "online" and not self._id:
399+
if self._user_config.run.mode == "online" and not self._id:
399400
raise RuntimeError("Expected identifier for run")
400401

401402
if not self._user_config.server.url:
@@ -456,7 +457,7 @@ def _online_dispatch_callback(
456457

457458
return (
458459
_online_dispatch_callback
459-
if self._mode == "online"
460+
if self._user_config.run.mode == "online"
460461
else _offline_dispatch_callback
461462
)
462463

@@ -473,10 +474,10 @@ def _start(self, reconnect: bool = False) -> bool:
473474
bool
474475
if successful
475476
"""
476-
if self._mode == "disabled":
477+
if self._user_config.run.mode == "disabled":
477478
return True
478479

479-
if self._mode != "offline":
480+
if self._user_config.run.mode != "offline":
480481
self._uuid = "notused"
481482

482483
logger.debug("Starting run")
@@ -631,7 +632,7 @@ def init(
631632
bool
632633
whether the initialisation was successful
633634
"""
634-
if self._mode == "disabled":
635+
if self._user_config.run.mode == "disabled":
635636
logger.warning(
636637
"Simvue monitoring has been deactivated for this run, metrics and artifacts will not be recorded."
637638
)
@@ -650,7 +651,7 @@ def init(
650651
"invalid visibility option, must be either None, 'public', 'tenant' or a list of users"
651652
)
652653

653-
if self._mode not in ("online", "offline"):
654+
if self._user_config.run.mode not in ("online", "offline"):
654655
self._error("invalid mode specified, must be online, offline or disabled")
655656
return False
656657

@@ -709,7 +710,7 @@ def init(
709710
self._simvue = Simvue(
710711
name=self._name,
711712
uniq_id=self._uuid,
712-
mode=self._mode,
713+
mode=self._user_config.run.mode,
713714
config=self._user_config,
714715
suppress_errors=self._suppress_errors,
715716
)
@@ -726,7 +727,7 @@ def init(
726727
if self._status == "running":
727728
self._start()
728729

729-
if self._mode == "online":
730+
if self._user_config.run.mode == "online":
730731
click.secho(
731732
f"[simvue] Run {self._name} created",
732733
bold=self._term_color,
@@ -941,7 +942,11 @@ def reconnect(self, run_id: str) -> bool:
941942

942943
self._id = run_id
943944
self._simvue = Simvue(
944-
self._name, self._id, self._mode, self._user_config, self._suppress_errors
945+
self._name,
946+
self._id,
947+
self._user_config.run.mode,
948+
self._user_config,
949+
self._suppress_errors,
945950
)
946951
self._start(reconnect=True)
947952

@@ -1192,7 +1197,7 @@ def _add_metrics_to_dispatch(
11921197
timestamp: typing.Optional[str] = None,
11931198
join_on_fail: bool = True,
11941199
) -> bool:
1195-
if self._mode == "disabled":
1200+
if self._user_config.run.mode == "disabled":
11961201
return True
11971202

11981203
# If there are no metrics to log just ignore

0 commit comments

Comments
 (0)