strongmind-platform-sdk 3.19.38 → 3.19.39
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/Gemfile +3 -0
- data/Gemfile.lock +5 -0
- data/lib/platform_sdk/sidekiq/ecs_task_protection_middleware.rb +52 -0
- data/lib/platform_sdk/sidekiq.rb +20 -0
- data/lib/platform_sdk/version.rb +1 -1
- data/lib/platform_sdk.rb +2 -0
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c66fa25807f8ef3dc617523c236691009327152fb4b76245c38a22b921bd3a6
|
4
|
+
data.tar.gz: f70482e271a58d856217d767d591ff876fdb37d0e445402ac3be72766e0ba665
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5b3d8024a2712b1f109d11342a81c260304f85e0a8261c6708b31d74b39c77d4ed03a604809c87ec5dce7381c7ff38440d970b43126f5a7748f815542368a04
|
7
|
+
data.tar.gz: 20ec372d4ae073f31fb177bd405f13b3f34baa6167774658738654eb8866503c047e5f32e012fe9efd0cba7dbdbf11da3e3267e8d7f55f2cafcab48026a74153
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -4,6 +4,7 @@ PATH
|
|
4
4
|
strongmind-platform-sdk (3.19.0)
|
5
5
|
activesupport (~> 7.1)
|
6
6
|
asset_sync
|
7
|
+
aws-sdk-cloudwatch
|
7
8
|
aws-sdk-secretsmanager (~> 1.66)
|
8
9
|
faraday (~> 2.5, >= 2.5.2)
|
9
10
|
faraday-retry
|
@@ -13,6 +14,7 @@ PATH
|
|
13
14
|
multi_json
|
14
15
|
rails (~> 7.1)
|
15
16
|
sentry-ruby
|
17
|
+
sidekiq
|
16
18
|
strongmind-oneroster-client (~> 2.0.1)
|
17
19
|
strongmind-sidekiq-cloudwatchmetrics
|
18
20
|
uri
|
@@ -362,6 +364,7 @@ PLATFORMS
|
|
362
364
|
|
363
365
|
DEPENDENCIES
|
364
366
|
activesupport (~> 7.1, >= 7.1.3.2)
|
367
|
+
aws-sdk-cloudwatch
|
365
368
|
factory_bot
|
366
369
|
faker
|
367
370
|
faraday
|
@@ -375,9 +378,11 @@ DEPENDENCIES
|
|
375
378
|
rspec-rails (~> 6.1.0)
|
376
379
|
rubocop
|
377
380
|
sentry-ruby
|
381
|
+
sidekiq
|
378
382
|
sqlite3 (~> 1.4)
|
379
383
|
strongmind-oneroster-client (~> 2.0.3)
|
380
384
|
strongmind-platform-sdk!
|
385
|
+
strongmind-sidekiq-cloudwatchmetrics
|
381
386
|
timecop
|
382
387
|
webmock
|
383
388
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
|
3
|
+
module PlatformSdk
|
4
|
+
module Sidekiq
|
5
|
+
|
6
|
+
class EcsTaskProtectionMiddleware
|
7
|
+
ECS_AGENT_URI = ENV['ECS_AGENT_URI']
|
8
|
+
STATE_ENDPOINT = "#{ECS_AGENT_URI}/task-protection/v1/state"
|
9
|
+
@@mutex = Mutex.new
|
10
|
+
@@active_jobs = 0
|
11
|
+
|
12
|
+
def call(_, _, _)
|
13
|
+
@@mutex.synchronize do
|
14
|
+
@@active_jobs += 1
|
15
|
+
set_task_protection(true) if @@active_jobs == 1
|
16
|
+
end
|
17
|
+
|
18
|
+
begin
|
19
|
+
yield
|
20
|
+
ensure
|
21
|
+
@@mutex.synchronize do
|
22
|
+
@@active_jobs -= 1
|
23
|
+
set_task_protection(false) if @@active_jobs == 0
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def set_task_protection(state)
|
31
|
+
begin
|
32
|
+
uri = URI.parse(STATE_ENDPOINT)
|
33
|
+
request = Net::HTTP::Put.new(uri)
|
34
|
+
request['Content-Type'] = 'application/json'
|
35
|
+
request.body = { 'ProtectionEnabled' => state }.to_json
|
36
|
+
|
37
|
+
response = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
38
|
+
http.request(request)
|
39
|
+
end
|
40
|
+
|
41
|
+
unless response.is_a?(Net::HTTPSuccess)
|
42
|
+
raise "Failed to update ECS task protection state: #{response.body}"
|
43
|
+
end
|
44
|
+
|
45
|
+
rescue StandardError => e
|
46
|
+
raise "An error occurred: #{e.message}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'sidekiq'
|
2
|
+
require 'sidekiq/cloud_watch_metrics'
|
3
|
+
|
4
|
+
module PlatformSdk
|
5
|
+
module Sidekiq
|
6
|
+
|
7
|
+
def self.send_metrics_to_cloudwatch!
|
8
|
+
::Sidekiq::CloudWatchMetrics.enable!
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure_task_protection
|
12
|
+
::Sidekiq.configure_server do |config|
|
13
|
+
config.server_middleware do |chain|
|
14
|
+
chain.add EcsTaskProtectionMiddleware
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/platform_sdk/version.rb
CHANGED
data/lib/platform_sdk.rb
CHANGED
@@ -21,6 +21,8 @@ require "platform_sdk/spec_support"
|
|
21
21
|
require "asset_sync"
|
22
22
|
require "fog-aws"
|
23
23
|
require "platform_sdk/asset_sync_initializer"
|
24
|
+
require "platform_sdk/sidekiq/ecs_task_protection_middleware"
|
25
|
+
require "platform_sdk/sidekiq"
|
24
26
|
|
25
27
|
module PlatformSdk
|
26
28
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strongmind-platform-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.19.
|
4
|
+
version: 3.19.39
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Platform Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -142,6 +142,34 @@ dependencies:
|
|
142
142
|
- - ">="
|
143
143
|
- !ruby/object:Gem::Version
|
144
144
|
version: '0'
|
145
|
+
- !ruby/object:Gem::Dependency
|
146
|
+
name: sidekiq
|
147
|
+
requirement: !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
type: :runtime
|
153
|
+
prerelease: false
|
154
|
+
version_requirements: !ruby/object:Gem::Requirement
|
155
|
+
requirements:
|
156
|
+
- - ">="
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
- !ruby/object:Gem::Dependency
|
160
|
+
name: aws-sdk-cloudwatch
|
161
|
+
requirement: !ruby/object:Gem::Requirement
|
162
|
+
requirements:
|
163
|
+
- - ">="
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: '0'
|
166
|
+
type: :runtime
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
requirements:
|
170
|
+
- - ">="
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
145
173
|
- !ruby/object:Gem::Dependency
|
146
174
|
name: strongmind-sidekiq-cloudwatchmetrics
|
147
175
|
requirement: !ruby/object:Gem::Requirement
|
@@ -274,6 +302,8 @@ files:
|
|
274
302
|
- lib/platform_sdk/power_school/client.rb
|
275
303
|
- lib/platform_sdk/power_school/special_program.rb
|
276
304
|
- lib/platform_sdk/sentry.rb
|
305
|
+
- lib/platform_sdk/sidekiq.rb
|
306
|
+
- lib/platform_sdk/sidekiq/ecs_task_protection_middleware.rb
|
277
307
|
- lib/platform_sdk/spec_support.rb
|
278
308
|
- lib/platform_sdk/spec_support/shared_examples/data_pipelineable_examples.rb
|
279
309
|
- lib/platform_sdk/spec_support/shared_examples/one_roster_data_pipelineable_examples.rb
|