multi_ec2_kiq 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa8f523926f920f85e754e199b9904a3eacc70d6
4
- data.tar.gz: 7d0a24414b0e95dd0de15ed6ca7c82e811b10479
3
+ metadata.gz: 5d54c1b4879b8e479d310c7ec683133f36d37a7b
4
+ data.tar.gz: fdbf905399aeec95547880cce90a9121ecb17037
5
5
  SHA512:
6
- metadata.gz: 6968fbbb2c98b5395afb1aa3b5280b18d6a74f3525c9208b43ecfa675f48cd670b149a066a5bacf2664b873c670007a8aea88ca2c8055fa4d4409cfa6b81adb5
7
- data.tar.gz: 29812526672914724243477ea0b3b27e3caa3fa2799fe4f45a85f20cfd84c073423721b638b86c5047740c26f6ae23bda40bd0f02d483df4726e526ffc0eca18
6
+ metadata.gz: da6234e855b50d9152ac1ebf5d8657a30602931b4193f65a38bacfed640725424e50803fd8a8b7d9ab67f3131926f1cbfe1c49505d5da51b80d7e2451c55c041
7
+ data.tar.gz: 4d148db6c7b87ed4f7aa4ee5dab855a65e6536d3bcffe1ed1951f744da077104e779667e89866ae9c2360861e88c7dd4469bcb212786eac8bbcd6d5363749605
data/README.md CHANGED
@@ -33,11 +33,17 @@ Or install it yourself as:
33
33
 
34
34
  ## Usage
35
35
 
36
- 1. You have to set aws profile in your ~/.aws/credentials.
37
-
38
- 2. Write configuration yml file, use "lib/settings.yml" as a reference.
39
-
40
- 3. Then, call methods.
36
+ You have to set aws profile in your ~/.aws/credentials.
37
+
38
+ Write configuration yml file, use "lib/settings.yml" as a reference.
39
+
40
+ To create ec2-status-table on DynamoDB, you have to call Dynamodb::create_status_table method from rails console, ruby source, e.t.c.
41
+ ```ruby
42
+ dynamodb = Dynamodb.new
43
+ dynamodb.create_status_table
44
+ ```
45
+
46
+ Then, call methods.
41
47
  ```ruby
42
48
  require "multi_ec2_kiq"
43
49
 
@@ -46,7 +52,7 @@ Or install it yourself as:
46
52
  MultiEc2Kiq.config_path = File.expand_path("your configuration file path", __FILE__)
47
53
  MultiEc2Kiq.start
48
54
  ```
49
-
55
+
50
56
  ```ruby
51
57
  require "multi_ec2_kiq"
52
58
 
@@ -1,3 +1,3 @@
1
1
  module MultiEc2Kiq
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -9,7 +9,6 @@ module MultiEc2Kiq
9
9
  end
10
10
 
11
11
  def started(instance_id)
12
- create_table_if_not_exists
13
12
  put_item(instance_id, @STATUS.started)
14
13
  true
15
14
  end
@@ -30,31 +29,7 @@ module MultiEc2Kiq
30
29
  true
31
30
  end
32
31
 
33
- private
34
-
35
- def raise_not_exist
36
- raise "instance_id doesn't exist on status table."
37
- end
38
-
39
- def get_item(instance_id)
40
- dynamodb.get_item(
41
- table_name: Settings.aws.dynamodb.status_table_name,
42
- key: {instance_id: instance_id}
43
- )
44
- end
45
-
46
- def put_item(instance_id, status)
47
- dynamodb.put_item(
48
- table_name: Settings.aws.dynamodb.status_table_name,
49
- item: {instance_id: instance_id, status: status}
50
- )
51
- end
52
-
53
- def create_table_if_not_exists
54
- dynamodb.list_tables.table_names.each {|table|
55
- return if table == Settings.aws.dynamodb.status_table_name
56
- }
57
-
32
+ def create_status_table
58
33
  options = {
59
34
  table_name: Settings.aws.dynamodb.status_table_name,
60
35
  key_schema: [
@@ -75,14 +50,40 @@ module MultiEc2Kiq
75
50
  }
76
51
  }
77
52
 
53
+ create_table(options, Settings.aws.dynamodb.status_table_name)
54
+
55
+ true
56
+ end
57
+
58
+ private
59
+
60
+ def create_table(options, table_name)
78
61
  dynamodb.create_table(options)
79
62
 
80
- dynamodb.wait_until(:table_exists, {table_name: Settings.aws.dynamodb.status_table_name}) do |w|
63
+ dynamodb.wait_until(:table_exists, {table_name: table_name}) do |w|
81
64
  w.max_attempts = 5
82
65
  w.delay = 5
83
66
  end
84
67
  end
85
68
 
69
+ def raise_not_exist
70
+ raise "instance_id doesn't exist on status table."
71
+ end
72
+
73
+ def get_item(instance_id)
74
+ dynamodb.get_item(
75
+ table_name: Settings.aws.dynamodb.status_table_name,
76
+ key: {instance_id: instance_id}
77
+ )
78
+ end
79
+
80
+ def put_item(instance_id, status)
81
+ dynamodb.put_item(
82
+ table_name: Settings.aws.dynamodb.status_table_name,
83
+ item: {instance_id: instance_id, status: status}
84
+ )
85
+ end
86
+
86
87
  def dynamodb
87
88
  @dynamodb ||= Aws::DynamoDB::Client.new(
88
89
  region: Settings.aws.dynamodb.region,
@@ -10,8 +10,13 @@ describe Dynamodb do
10
10
  @dynamodb = Dynamodb.new
11
11
  end
12
12
 
13
+ it 'should create statud table.' do
14
+ expect(@dynamodb).to receive(:create_table).with(anything, anything)
15
+ result = @dynamodb.create_status_table
16
+ expect(result).to eq(true)
17
+ end
18
+
13
19
  it 'should write started.' do
14
- expect(@dynamodb).to receive(:create_table_if_not_exists)
15
20
  expect(@dynamodb).to receive(:put_item).with(anything, anything)
16
21
  result = @dynamodb.started("instance_test")
17
22
  expect(result).to eq(true)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_ec2_kiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - SrcHndWng