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

Instance Method Details

#load_component_stateObject

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

Raises:

  • (NotImplementedError)


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_stateObject

These methods must be implemented by including classes

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/datadog/ci/utils/stateful.rb', line 38

def serialize_state
  raise NotImplementedError, "Components must implement #serialize_state"
end

#storage_keyObject

Raises:

  • (NotImplementedError)


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_stateObject

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