web47core 3.2.3.1 → 3.2.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd88813680f4b954ca7f7989d94d7c812684f0b38318f26098b9202dc4af5fe6
4
- data.tar.gz: 7611ff98b75954c64687df26960259ba82d1b79652afd644953952ee04a96bd0
3
+ metadata.gz: 2b92b99e81e9fe10ed19f01ec7dcdd2d949b23530b42e7b59f9657ec36cb6f99
4
+ data.tar.gz: e4def330da1ef103c2bb3fba322b8620957ef7644115ace307d0a0ff89b38a5d
5
5
  SHA512:
6
- metadata.gz: bb8312761cae0d617cbb08a6356a24ec571e3ba13b21ddfa038c6187b042aa1f3244c9a8deefd1d28c4e029d1c9326f0a04e33b2ebbe38a7d4989ce4de4a9035
7
- data.tar.gz: 7ed3840403c8d51b29d1f7bbcdc1c49212154ad645105a3be113d2e9a57a9c39547eeec575aa8c7b63d2d47c3132f33b917b879611e5d22ce81556dc542637dc
6
+ metadata.gz: 4a4fd7f1be5bab10b325337cdf8a3504e1fa39ac147a0894a41922ce52cdc6f160f59e800bc68ab3557157daf0a60d0325c2b72e34a3fa858726e9f03f040302
7
+ data.tar.gz: 3a2219fac645965efa6c5434571b9b368fb8dfc6ca0ca481b6b7cbc2b9bea38824b10c9d4623deaa8066eae397393ce706de5d75ea84a410dd9a9385466379fe
@@ -153,22 +153,13 @@ module Cron
153
153
  def check_auto_scale
154
154
  return unless auto_scaling_configured?
155
155
 
156
- if delayed_jobs_count.eql?(0)
156
+ if delayed_jobs_count.zero?
157
157
  handle_zero_job_count
158
158
  else
159
159
  handle_auto_scale_jobs
160
160
  end
161
161
  end
162
162
 
163
- #
164
- # Returns the AWS AutoScaling Client
165
- #
166
- def client
167
- @client ||= Aws::AutoScaling::Client.new(access_key_id: sys_config.aws_access_key_id,
168
- secret_access_key: sys_config.aws_secret_access_key,
169
- region: sys_config.aws_region)
170
- end
171
-
172
163
  def sys_config
173
164
  @sys_config ||= SystemConfiguration.configuration
174
165
  end
@@ -191,29 +182,27 @@ module Cron
191
182
  false
192
183
  end
193
184
 
194
- #
195
- # Returns the AutoScalingGroup associated with the account
196
- #
197
- def auto_scaling_group
198
- filter = { auto_scaling_group_names: [sys_config.aws_auto_scaling_group_name] }
199
- @auto_scaling_group ||= client.describe_auto_scaling_groups(filter).auto_scaling_groups.first
185
+ # @abstract Returns the AWS ECS service
186
+ # @return [Aws::ECS::Types::Service]
187
+ def ecs_service
188
+ filter = { cluster: sys_config.aws_ecs_cluster_worker_name, services: [sys_config.aws_ecs_service_worker_name] }
189
+ @ecs_service ||= ecs_client.describe_services(filter).services.first
200
190
  end
201
191
 
202
- #
203
- # Returns a count of the Delayed Jobs in queue that have not failed
204
- #
192
+ # @abstract Returns a count of the Delayed Jobs in queue that have not failed
193
+ # @return [Integer]
205
194
  def delayed_jobs_count
206
195
  @delayed_jobs_count ||= Delayed::Backend::Mongoid::Job.where(failed_at: nil).read(mode: :primary).count
207
196
  end
208
197
 
209
- #
210
- # Returns the current value of 'desired capacity' for the AutoScalingGroup
211
- #
198
+ # @abstract Returns the current value of 'desired capacity' for the ECS Service
199
+ # @return [Integer]
212
200
  def current_desired_capacity
213
- current = auto_scaling_group.desired_capacity
201
+ current = ecs_service.desired_count
214
202
  set current_server_count: current
215
203
  current
216
204
  rescue StandardError
205
+ puts 'error on desirect capacy'
217
206
  0
218
207
  end
219
208
 
@@ -221,7 +210,7 @@ module Cron
221
210
  # Calls the 'auto_scale' method with a 'desired_count' of 0 unless the capacity is already at 0
222
211
  #
223
212
  def handle_zero_job_count
224
- return if current_desired_capacity.eql?(0)
213
+ return if current_desired_capacity.zero?
225
214
 
226
215
  auto_scale
227
216
  end
@@ -231,29 +220,33 @@ module Cron
231
220
  # We don't need any more workers if the job count is less than 1,000
232
221
  #
233
222
  def handle_auto_scale_jobs
234
- return if delayed_jobs_count < 50
223
+ return if delayed_jobs_count.zero?
235
224
 
236
225
  case delayed_jobs_count
237
- when 50..250
226
+ when 1..50
238
227
  auto_scale(1)
239
- when 251..500
228
+ when 51..200
240
229
  auto_scale(2)
241
- when 501..1_000
230
+ when 201..500
242
231
  auto_scale(3)
243
- when 1_001..2_000
232
+ when 501..1_000
244
233
  auto_scale(4)
245
- when 2_001..3_999
234
+ when 1_001..2_000
246
235
  auto_scale(4)
247
- when 4_000..7_999
236
+ when 2_001..3_000
248
237
  auto_scale(5)
249
- when 8_000..10_999
238
+ when 3_001..4_000
250
239
  auto_scale(5)
251
- when 11_000..13_999
252
- auto_scale(6)
253
- when 14_000..17_999
240
+ when 4_001..6_000
254
241
  auto_scale(6)
255
- else
242
+ when 6_001..8_000
256
243
  auto_scale(7)
244
+ when 8_001..10_000
245
+ auto_scale(8)
246
+ when 10_001..13_000
247
+ auto_scale(9)
248
+ else
249
+ auto_scale(10)
257
250
  end
258
251
  end
259
252
 
@@ -265,11 +258,11 @@ module Cron
265
258
  # Make sure we don't remove any workers with assigned jobs by accident
266
259
  return if desired_count.positive? && desired_count <= current_desired_capacity
267
260
 
268
- client.update_auto_scaling_group(auto_scaling_group_name: sys_config.aws_auto_scaling_group_name,
269
- min_size: desired_count,
270
- desired_capacity: desired_count)
261
+ ecs_client.update_service(cluster: sys_config.aws_ecs_cluster_worker_name,
262
+ service: sys_config.aws_ecs_service_worker_name,
263
+ desired_count: desired_count)
271
264
  rescue StandardError => error
272
- App47Logger.log_error "Unable to set auto scaler to #{desired_count}", error
265
+ App47Logger.log_error "Unable to set ECS service auto scaler to #{desired_count}", error
273
266
  end
274
267
 
275
268
  #
@@ -299,5 +292,11 @@ module Cron
299
292
  def ensure_last_check_in
300
293
  self.last_check_in_at ||= Time.now.utc
301
294
  end
295
+
296
+ # @abstract Returns the AWS ECS client
297
+ # @return [Aws::ECS::Client]
298
+ def ecs_client
299
+ @ecs_client ||= sys_config.aws_ecs_client
300
+ end
302
301
  end
303
302
  end
@@ -14,8 +14,9 @@ module AwsConfiguration
14
14
  field :aws_region, type: String
15
15
  field :aws_access_key_id, type: String
16
16
  field :aws_secret_access_key, type: String
17
- field :aws_auto_scaling_group_name, type: String
18
17
  field :aws_bucket_name, type: String
18
+ field :aws_ecs_cluster_worker_name, type: String
19
+ field :aws_ecs_service_worker_name, type: String
19
20
  end
20
21
  end
21
22
 
@@ -37,12 +38,11 @@ module AwsConfiguration
37
38
  # Determine if auto scaling group is configured
38
39
  #
39
40
  def aws_auto_scaling_configured?
40
- aws_configured? && aws_auto_scaling_group_name.present?
41
+ aws_configured? && aws_ecs_cluster_worker_name.present? && aws_ecs_service_worker_name.present?
41
42
  end
42
43
 
43
- #
44
- # AWS client.
45
- #
44
+ # @abstract EC2 Client
45
+ # @return [Aws::EC2::Client]
46
46
  def aws_ec2_client
47
47
  return nil unless aws_configured?
48
48
 
@@ -51,16 +51,33 @@ module AwsConfiguration
51
51
  aws_secret_access_key))
52
52
  end
53
53
 
54
- #
55
- # S3 Client
56
- #
54
+ # @abstract S3 Client
55
+ # @return [Aws::S3::Client]
57
56
  def aws_s3_client
58
57
  return nil unless aws_configured?
59
58
 
60
- # We want this to remake itself each time because it is possible that the
61
- # => user would change the access keys in between actions. Huh?
62
59
  @aws_s3_client ||= Aws::S3::Client.new(region: aws_region,
63
60
  access_key_id: aws_access_key_id,
64
61
  secret_access_key: aws_secret_access_key)
65
62
  end
63
+
64
+ # @abstract ECS Client
65
+ # @return [Aws::ECS::Client]
66
+ def aws_ecs_client
67
+ return nil unless aws_configured?
68
+
69
+ @aws_s3_client ||= Aws::ECS::Client.new(region: aws_region,
70
+ access_key_id: aws_access_key_id,
71
+ secret_access_key: aws_secret_access_key)
72
+ end
73
+
74
+ # @abstract AutoScaling Client
75
+ # @return [Aws::AutoScaling::Client]
76
+ def aws_auto_scale_client
77
+ return nil unless aws_configured?
78
+
79
+ @auto_scale_client ||= Aws::AutoScaling::Client.new(access_key_id: aws_access_key_id,
80
+ secret_access_key: aws_secret_access_key,
81
+ region: aws_region)
82
+ end
66
83
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Web47core
4
- VERSION = '3.2.3.1'
4
+ VERSION = '3.2.3.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: web47core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.3.1
4
+ version: 3.2.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Schroeder
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: aws-sdk-autoscaling
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: cancancan
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -234,6 +220,20 @@ dependencies:
234
220
  - - ">="
235
221
  - !ruby/object:Gem::Version
236
222
  version: '0'
223
+ - !ruby/object:Gem::Dependency
224
+ name: aws-sdk-ecs
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: brakeman
239
239
  requirement: !ruby/object:Gem::Requirement