multi_ec2_kiq 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +12 -6
- data/lib/multi_ec2_kiq/version.rb +1 -1
- data/lib/threads/dynamodb.rb +28 -27
- data/spec/threads/dynamodb_spec.rb +6 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d54c1b4879b8e479d310c7ec683133f36d37a7b
|
4
|
+
data.tar.gz: fdbf905399aeec95547880cce90a9121ecb17037
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
|
data/lib/threads/dynamodb.rb
CHANGED
@@ -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
|
-
|
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:
|
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)
|