Skip to content

Commit

Permalink
Introduce BackendStateLifecycle abstraction
Browse files Browse the repository at this point in the history
This replaces StateLifecycle.
The concept of assets is removed from the API. Each services that does
operations with the state handles the level of persistence to support
(and therefore, the deep persistence)
  • Loading branch information
giograno committed May 21, 2022
1 parent 46adaab commit 21e919f
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions localstack/services/plugins.py
Expand Up @@ -133,11 +133,26 @@ def on_exception(self):
pass


class StateLifecycle:
def retrieve_state(self):
pass
class BaseBackendStateLifecycle(abc.ABC):
"""
Interface that supports the retrieval, injection and restore of the backend for services.
"""

@abc.abstractmethod
def retrieve_state(self, **args):
"""Retrieves a backend for an account, region and service"""

def inject_state(self, state):
@abc.abstractmethod
def inject_state(self, **args):
"""Injects a backend for an account, region and service"""

@abc.abstractmethod
def reset_state(self):
"""Resets a backend for an account, region and service"""

@abc.abstractmethod
def on_after_reset(self):
"""Performed after the reset of a service"""
pass


Expand All @@ -151,7 +166,7 @@ def __init__(
active=False,
stop=None,
lifecycle_hook: ServiceLifecycleHook = None,
state_lifecycle: StateLifecycle = None,
backend_state_lifecycle: BaseBackendStateLifecycle = None,
):
self.plugin_name = name
self.start_function = start
Expand All @@ -160,7 +175,7 @@ def __init__(
self.default_active = active
self.stop_function = stop
self.lifecycle_hook = lifecycle_hook or ServiceLifecycleHook()
self.state_lifecycle = state_lifecycle
self.backend_state_lifecycle = backend_state_lifecycle
call_safe(self.lifecycle_hook.on_after_init)

def start(self, asynchronous):
Expand Down

0 comments on commit 21e919f

Please sign in to comment.