ecs-easy-cluster 0.0.3 → 0.0.4

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: 637c62d07ff46b73c2fb3a6c56dbc6bdde20bb64
4
- data.tar.gz: 6ade21bcd624fa7a08439fc51a53865e207bcb5c
3
+ metadata.gz: a16a8b4f530e203e99ec31aa3c2b4f55e18cc42b
4
+ data.tar.gz: 6cc1b2c1c06e6a39912206544ca2dc95eb40e0ba
5
5
  SHA512:
6
- metadata.gz: 5951dd1af32d8c4aea7bf55911080eb120d0622e36d30061f4cd0823fe1417605a113752aee29ecfab5e079699704980325e3649f46ed55f541717dd6e4f598a
7
- data.tar.gz: 9f053297c904201d384541c22e72cb694f781d81d4eefbceaccdb2afeb6fab1ac4431a78dbab0e4f3fe594c5edfc4727cb95b73ec8997a753571743794280432
6
+ metadata.gz: cb4d9383c09a413fa137e32a878dbff86a6352a3243da85d0d5bbeb24033633aaeb0478c38f507d728ee1f2a85baa307192d72d239263e9f7b70dff300fda378
7
+ data.tar.gz: a2c89af6d47072ef66aa8d9742a7bf9727d45cb5187bfa63a104572015ab1839c4280f4044121eb8b3d52726f0b60d8df8678e966bd68f7f16df07dbd9c65d89
@@ -156,13 +156,5 @@ module Ecs::Easy::Cluster
156
156
  puts e
157
157
  end
158
158
 
159
- private
160
- def fail_reason( failures )
161
- reasons = failures.map {|f| f.reason }
162
- if reasons.include?( "RESOURCE:MEMORY" )
163
- return "RESOURCE:MEMORY"
164
- end
165
- end
166
-
167
159
  end
168
160
  end
@@ -1,6 +1,27 @@
1
1
  module Ecs::Easy::Cluster
2
2
  class MemScale < Base
3
3
 
4
+ class CannotStartTaskError < StandardError
5
+ attr_reader :result
6
+ def initialize( result )
7
+ @result = result
8
+ end
9
+
10
+ def failures
11
+ return nil unless result
12
+ result.failures
13
+ end
14
+
15
+ def fail_reason
16
+ return nil if failures.empty?
17
+ reasons = failures.map {|f| f.reason }
18
+ if reasons.include?( "RESOURCE:MEMORY" )
19
+ return "RESOURCE:MEMORY"
20
+ end
21
+ nil
22
+ end
23
+ end
24
+
4
25
  EC2_PROFILE_PATH = File.expand_path("../config/ec2_profile.json", __FILE__)
5
26
  INSTANCE_TYPES = JSON.parse(File.read( EC2_PROFILE_PATH ))
6
27
 
@@ -11,33 +32,37 @@ module Ecs::Easy::Cluster
11
32
  end
12
33
  end
13
34
 
14
- res = nil
15
- 3.times do
35
+ retry_count = 3
36
+ begin
16
37
  wait_until_ready
17
38
  res = run_task!( task_definition, overrides )
18
- break if res.failures.empty?
19
- puts "Failed to run the task. Try again."
20
- sleep 5
21
- end
22
-
23
- # Failure because some reasons
24
- unless res.failures.empty?
25
- puts res.failures
26
- case fail_reason(res.failures)
39
+ unless res.failures.empty?
40
+ raise CannotStartTaskError.new( res )
41
+ end
42
+ rescue CannotStartTaskError => e
43
+ puts e.failures
44
+ case e.fail_reason
27
45
  when "RESOURCE:MEMORY"
28
46
  puts "No enough memory on current container instances to execute this task. Add another container instance automatically."
29
47
 
30
48
  if num_instances >= max_instances
31
- raise "Could\'t scale more instances because it reaches maximum instances. You should upgrade the maximum number of instance to execute multiple tasks at the same time."
49
+ puts "Couldn\'t scale more instances because it reaches maximum instances. You should upgrade the maximum number of instance to execute multiple tasks at the same time."
32
50
  end
33
51
  unless acceptable_task?( task_definition )
34
- raise "Could\'t accept this task because of the lack of memory. You should upgrade ec2 instance type."
52
+ raise "Couldn\'t accept this task because of the lack of memory. You should upgrade ec2 instance type."
35
53
  end
36
54
 
37
55
  scale!
38
56
  else
39
- raise "Unknown reason: #{res.failures}"
57
+ raise "Unknown reason: #{e.failures}"
40
58
  end
59
+
60
+ puts "Failed to run the task. Try again."
61
+ sleep 10
62
+ retry_count -= 1
63
+ retry if retry_count > 0
64
+ rescue => e
65
+ raise "Unknown reason: #{e}"
41
66
  end
42
67
 
43
68
  res
@@ -1,7 +1,7 @@
1
1
  module Ecs
2
2
  module Easy
3
3
  module Cluster
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.4"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecs-easy-cluster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - metheglin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-24 00:00:00.000000000 Z
11
+ date: 2017-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk