Class: MultiEc2Kiq::Dynamodb
- Inherits:
-
Object
- Object
- MultiEc2Kiq::Dynamodb
- Defined in:
- lib/threads/dynamodb.rb
Instance Method Summary collapse
- #create_status_table ⇒ Object
-
#initialize ⇒ Dynamodb
constructor
A new instance of Dynamodb.
- #started(instance_id) ⇒ Object
- #stopped(instance_id) ⇒ Object
- #wait_until_to_stop(instance_id) ⇒ Object
Constructor Details
#initialize ⇒ Dynamodb
Returns a new instance of Dynamodb.
7 8 9 |
# File 'lib/threads/dynamodb.rb', line 7 def initialize @STATUS = OpenStruct.new(started: "started", stopped: "stopped", to_stop: "to_stop") end |
Instance Method Details
#create_status_table ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/threads/dynamodb.rb', line 32 def create_status_table = { table_name: Settings.aws.dynamodb.status_table_name, key_schema: [ { attribute_name: "instance_id", key_type: "HASH" } ], attribute_definitions: [ { attribute_name: "instance_id", attribute_type: "S" } ], provisioned_throughput: { read_capacity_units: 1, write_capacity_units: 1 } } create_table(, Settings.aws.dynamodb.status_table_name) true end |
#started(instance_id) ⇒ Object
11 12 13 14 |
# File 'lib/threads/dynamodb.rb', line 11 def started(instance_id) put_item(instance_id, @STATUS.started) true end |
#stopped(instance_id) ⇒ Object
26 27 28 29 30 |
# File 'lib/threads/dynamodb.rb', line 26 def stopped(instance_id) raise_not_exist if !get_item(instance_id).item put_item(instance_id, @STATUS.stopped) true end |
#wait_until_to_stop(instance_id) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/threads/dynamodb.rb', line 16 def wait_until_to_stop(instance_id) (0...Settings.wait_to_stop.max_attempts).each{|i| data = get_item(instance_id) raise_not_exist if !data.item return true if data.item["status"] == @STATUS.to_stop sleep(Settings.wait_to_stop.delay) } false end |