Module: Datadog::CI::Utils::Stateful
- Included in:
- Remote::Component, TestImpactAnalysis::Component, TestManagement::Component, TestTracing::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_cached_known_tests ⇒ Object
- #load_cached_settings ⇒ Object
- #load_cached_skippable_tests ⇒ Object
- #load_cached_test_management ⇒ Object
-
#load_component_state ⇒ Object
Load component state.
- #restore_state(state) ⇒ Object
- #restore_state_from_datadog_test_runner ⇒ Object
-
#serialize_state ⇒ Object
These methods must be implemented by including classes.
- #storage_key ⇒ Object
-
#store_component_state ⇒ Object
Store component state.
- #test_optimization_cache ⇒ Object
Instance Method Details
#load_cached_known_tests ⇒ Object
63 64 65 |
# File 'lib/datadog/ci/utils/stateful.rb', line 63 def load_cached_known_tests test_optimization_cache.load_known_tests end |
#load_cached_settings ⇒ Object
59 60 61 |
# File 'lib/datadog/ci/utils/stateful.rb', line 59 def load_cached_settings test_optimization_cache.load_settings end |
#load_cached_skippable_tests ⇒ Object
71 72 73 |
# File 'lib/datadog/ci/utils/stateful.rb', line 71 def load_cached_skippable_tests test_optimization_cache.load_skippable_tests end |
#load_cached_test_management ⇒ Object
67 68 69 |
# File 'lib/datadog/ci/utils/stateful.rb', line 67 def load_cached_test_management test_optimization_cache.load_test_management end |
#load_component_state ⇒ Object
Load component state
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/datadog/ci/utils/stateful.rb', line 21 def load_component_state if test_optimization_cache.cache_available? Datadog.logger.debug { "Test Optimization cache found" } return true if restore_state_from_datadog_test_runner end test_tracing_component = Datadog.send(:components).test_tracing return false unless test_tracing_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
47 48 49 |
# File 'lib/datadog/ci/utils/stateful.rb', line 47 def restore_state(state) raise NotImplementedError, "Components must implement #restore_state" end |
#restore_state_from_datadog_test_runner ⇒ Object
55 56 57 |
# File 'lib/datadog/ci/utils/stateful.rb', line 55 def restore_state_from_datadog_test_runner false end |
#serialize_state ⇒ Object
These methods must be implemented by including classes
43 44 45 |
# File 'lib/datadog/ci/utils/stateful.rb', line 43 def serialize_state raise NotImplementedError, "Components must implement #serialize_state" end |
#storage_key ⇒ Object
51 52 53 |
# File 'lib/datadog/ci/utils/stateful.rb', line 51 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 |
#test_optimization_cache ⇒ Object
75 76 77 |
# File 'lib/datadog/ci/utils/stateful.rb', line 75 def test_optimization_cache Datadog.send(:components).test_optimization_cache end |