Skip to content

Use base class for Online and Offline#151

Merged
kzscisoft merged 10 commits intosupport_v2_serverfrom
feature/148-offline-online-subclasses
Mar 5, 2024
Merged

Use base class for Online and Offline#151
kzscisoft merged 10 commits intosupport_v2_serverfrom
feature/148-offline-online-subclasses

Conversation

@kzscisoft
Copy link
Collaborator

The Simvue function which chooses between offline and online versions of the core functionality now selects between two classes which inherit from a common base class.
This has the advantage of ensuring that methods are present in both and the Simvue client requires no knowledge of which it is using calling the inherited methods.
The code for these changes can be found within the simvue/factory sub-directory.

simvue.factory

class SimvueBaseClass(abc.ABC):
    @abc.abstractmethod
    def __init__(self, name: str, uniq_id: uuid.UUID, suppress_errors: bool) -> None:
        self._logger = logging.getLogger(f"simvue.{self.__class__.__name__}")
        self._suppress_errors: bool = suppress_errors
        self._uuid: str = uniq_id
        self._name: str = name
        self._id: typing.Optional[int] = None
        self._aborted: bool = False

    def _error(self, message: str) -> None:
        """
        Raise an exception if necessary and log error
        """
        if not self._suppress_errors:
            raise RuntimeError(message)
        else:
            self._logger.error(message)
            self._aborted = True

    @abc.abstractmethod
    def create_run(self, data: dict[str, typing.Any]) -> typing.Optional[dict[str, typing.Any]]:
        pass
    
    ...

@kzscisoft kzscisoft added the enhancement New feature or request label Jan 22, 2024
@kzscisoft kzscisoft linked an issue Jan 22, 2024 that may be closed by this pull request
11 tasks
@kzscisoft kzscisoft mentioned this pull request Jan 22, 2024
11 tasks
@alahiff
Copy link
Collaborator

alahiff commented Feb 28, 2024

There is extensive use of skip_if_failed in simvue/factory/remote.py but skip_if_failed isn't actually defined:

  File "/Users/andrewlahiff/Work/Observability/client_check_151_v2/client/simvue/run.py", line 17, in <module>
    from .factory import Simvue
  File "/Users/andrewlahiff/Work/Observability/client_check_151_v2/client/simvue/factory/__init__.py", line 1, in <module>
    from .remote import Remote
  File "/Users/andrewlahiff/Work/Observability/client_check_151_v2/client/simvue/factory/remote.py", line 6, in <module>
    from simvue.utilities import (
ImportError: cannot import name 'skip_if_failed' from 'simvue.utilities' 

@kzscisoft
Copy link
Collaborator Author

There is extensive use of skip_if_failed in simvue/factory/remote.py but skip_if_failed isn't actually defined:

  File "/Users/andrewlahiff/Work/Observability/client_check_151_v2/client/simvue/run.py", line 17, in <module>
    from .factory import Simvue
  File "/Users/andrewlahiff/Work/Observability/client_check_151_v2/client/simvue/factory/__init__.py", line 1, in <module>
    from .remote import Remote
  File "/Users/andrewlahiff/Work/Observability/client_check_151_v2/client/simvue/factory/remote.py", line 6, in <module>
    from simvue.utilities import (
ImportError: cannot import name 'skip_if_failed' from 'simvue.utilities' 

I have re-added the missing function

@alahiff
Copy link
Collaborator

alahiff commented Mar 4, 2024

References to get_server_version in simvue/factory/remote.py need to be removed as get_server_version no longer exists:

diff --git a/simvue/factory/remote.py b/simvue/factory/remote.py
index 711fd64..7f6470c 100644
--- a/simvue/factory/remote.py
+++ b/simvue/factory/remote.py
@@ -7,7 +7,6 @@ from simvue.utilities import (
     get_auth,
     get_expiry,
     prepare_for_api,
-    get_server_version,
     skip_if_failed,
 )
 from simvue.factory.base import SimvueBaseClass
@@ -34,7 +33,6 @@ class Remote(SimvueBaseClass):
         self._headers_mp: dict[str, str] = self._headers | {
             "Content-Type": "application/msgpack"
         }
-        self._version: typing.Optional[int] = get_server_version()
         super().__init__(name, uniq_id, suppress_errors)
 
     @skip_if_failed("_aborted", "_suppress_errors", (None, None))

@alahiff
Copy link
Collaborator

alahiff commented Mar 4, 2024

There's an argument to Remote missing in simvue/sender.py:

diff --git a/simvue/sender.py b/simvue/sender.py
index 101ca89..7375607 100644
--- a/simvue/sender.py
+++ b/simvue/sender.py
@@ -103,7 +103,7 @@ def sender():
         else:
             logger.info('Considering run with no name yet and id %s', id)
 
-        remote = Remote(run_init['name'], id, suppress_errors=True)
+        remote = Remote(run_init['name'], id, "offline", suppress_errors=True)
 
         # Check token
         remote.check_token()

Copy link
Collaborator

@alahiff alahiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After making some small corrections and adding my recent work on offline mode, I'm happy.

@kzscisoft kzscisoft merged commit eeac57b into support_v2_server Mar 5, 2024
@kzscisoft kzscisoft deleted the feature/148-offline-online-subclasses branch March 5, 2024 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simvue v2 Refactor

2 participants