Module: Datadog::CI::Utils::Stateful
- Included in:
- Remote::Component, TestManagement::Component, TestOptimisation::Component, TestVisibility::Component
- Defined in:
- lib/datadog/ci/utils/stateful.rb
Overview
Module for components that need to persist and restore state
Instance Method Summary collapse
-
#load_component_state ⇒ Object
Load component state.
- #restore_state(state) ⇒ Object
-
#serialize_state ⇒ Object
These methods must be implemented by including classes.
- #storage_key ⇒ Object
-
#store_component_state ⇒ Object
Store component state.
Instance Method Details
#load_component_state ⇒ Object
Load component state
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/datadog/ci/utils/stateful.rb', line 21 def load_component_state test_visibility_component = Datadog.send(:components).test_visibility return false unless test_visibility_component.client_process? state = Utils::FileStorage.retrieve(storage_key) unless state Datadog.logger.debug { "No component state found in file storage (key=#{storage_key})" } return false end restore_state(state) Datadog.logger.debug { "Loaded component state from file storage (key=#{storage_key})" } true end |
#restore_state(state) ⇒ Object
42 43 44 |
# File 'lib/datadog/ci/utils/stateful.rb', line 42 def restore_state(state) raise NotImplementedError, "Components must implement #restore_state" end |
#serialize_state ⇒ Object
These methods must be implemented by including classes
38 39 40 |
# File 'lib/datadog/ci/utils/stateful.rb', line 38 def serialize_state raise NotImplementedError, "Components must implement #serialize_state" end |
#storage_key ⇒ Object
46 47 48 |
# File 'lib/datadog/ci/utils/stateful.rb', line 46 def storage_key raise NotImplementedError, "Components must implement #storage_key" end |
#store_component_state ⇒ Object
Store component state
11 12 13 14 15 16 17 18 |
# File 'lib/datadog/ci/utils/stateful.rb', line 11 def store_component_state state = serialize_state res = Utils::FileStorage.store(storage_key, state) Datadog.logger.debug { "Stored component state (key=#{storage_key}): #{res}" } res end |