Class: Rbcli::State::DynamoDBStorage
- Inherits:
-
StateStorage
- Object
- StateStorage
- Rbcli::State::DynamoDBStorage
- Defined in:
- lib/rbcli/state_storage/remotestate_dynamodb.rb
Defined Under Namespace
Classes: RemoteStateError
Instance Method Summary collapse
- #create_state ⇒ Object
- #error(text) ⇒ Object
- #load_state ⇒ Object
- #lock ⇒ Object
- #save_state ⇒ Object
- #state_exists? ⇒ Boolean
-
#state_subsystem_init ⇒ Object
def initialize dynamodb_table, region, force_creation: false, halt_on_error: true.
- #unlock ⇒ Object
Methods inherited from StateStorage
#[], #[]=, #clear, #commit, #delete, #disconnect, #each, #initialize, #key?, #rbclidata, #refresh, #set_rbclidata, #to_h, #to_s
Constructor Details
This class inherits a constructor from Rbcli::State::StateStorage
Instance Method Details
#create_state ⇒ Object
63 64 65 66 67 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 63 def create_state make_dynamo_call do @dynamodb.create_table end end |
#error(text) ⇒ Object
89 90 91 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 89 def error text raise RemoteStateError.new "Error accessing remote state: #{text}" end |
#load_state ⇒ Object
69 70 71 72 73 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 69 def load_state make_dynamo_call do @data = @dynamodb.get_object.deep_symbolize! end end |
#lock ⇒ Object
81 82 83 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 81 def lock @dynamodb.lock_or_wait if @locking end |
#save_state ⇒ Object
75 76 77 78 79 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 75 def save_state make_dynamo_call do @dynamodb.save_object @data end end |
#state_exists? ⇒ Boolean
58 59 60 61 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 58 def state_exists? return false unless make_dynamo_call { @dynamodb.table_exists? } make_dynamo_call { @dynamodb.object_exists? } end |
#state_subsystem_init ⇒ Object
def initialize dynamodb_table, region, force_creation: false, halt_on_error: true
# Set defaults in Rbcli’s config Rbcli::State::RemoteStorage::Connectors::DynamoDB.save_defaults
# Create DynamoDB Connector @dynamodb = Rbcli::State::RemoteStorage::Connectors::DynamoDB.new dynamodb_table, region, Rbcli::config, Rbcli::config
super dynamodb_table, force_creation: force_creation, halt_on_error: halt_on_error end
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 46 def state_subsystem_init @locking = Rbcli.configuration(:storage, :remotestate_init_params)[:locking] dynamodb_table = Rbcli.configuration(:storage, :remotestate_init_params)[:dynamodb_table] region = Rbcli.configuration(:storage, :remotestate_init_params)[:region] # Set defaults in Rbcli's config Rbcli::State::RemoteConnectors::DynamoDB.save_defaults # Create DynamoDB Connector @dynamodb = Rbcli::State::RemoteConnectors::DynamoDB.new dynamodb_table, region, Rbcli::config[:aws_access_key_id], Rbcli::config[:aws_secret_access_key], locking: Rbcli.configuration(:storage, :remotestate_init_params)[:locking] end |
#unlock ⇒ Object
85 86 87 |
# File 'lib/rbcli/state_storage/remotestate_dynamodb.rb', line 85 def unlock @dynamodb.unlock if @locking end |