Sign in or sign up before continuing. Don't have an account yet? Register now to get started.
Register now

Implement simulation mode

tl;dr: I won't work on this in the foreseeable future. MRs for a generic Simulation Controller implementation are welcome.

History

The previous SiLA 2 implementation in Python always generated two feature implementation templates: A real and a simulation implemenation. It also always implemented the Simulation Controller core feature, which would just forward all calls to either of the two implementations.

Simulation Controller core feature: Switch at runtime

I don't agree with the choice to have a runtime switch between both modes by default. Implementing such thing properly is non-trivial because both modes could require startup/shutdown routines, and all running commands and ongoing property subscriptions would have to be finished before switching. The previous implementation just ignored all of these complexities.

There might be use cases where such behavior is wanted, but supporting this with a generic implementation in this library is not a high priority for me. Server implementations can do this by themselves in the specific ways they want to have it.

CLI switch

If a server process does not need to switch the mode at runtime, a CLI switch in the server package would suffice, e.g. python -m my_sila2_server --simulation. This can be trivially implemented with the current state of this library:

# in __main__.py
def main(
    ...,
    simulation: bool = Option(False, "--simulation", help="Start the server in simulation mode")
):
    ...
    server = Server(..., simulation=simulation)

# in server.py
class Server(SilaServer):
    def __init__(..., simulation: bool):
        ...
        if simulation:
            self.greetingprovider = GreetingProviderSimulation(self)
        else:
            self.greetingprovider = GreetingProviderImpl(self)

        self.set_feature_implementation(GreetingProviderFeature, self.greetingProvider)
Edited Sep 12, 2022 by Niklas Mertsch
Assignee Loading
Time tracking Loading