herdst_worker 0.2.12 → 0.2.14
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: abe8b9c33c17e39eb8f3bc453f59867a813bad52d273ade952cb416ae9e6a8bb
|
|
4
|
+
data.tar.gz: 779373f610f0220af5b4abe3b0dc78d982d56ee9c8424bc6b9f1ae7c53fd76dd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee12d5784b12a07a25f3b0f322faf547e0bd6158a01c1e33ba26419df97ace4e17bd4287eed4c68fbf8a28bc7e8dbd5bb47402f47fb9b52250e8ca9b58a37ea7
|
|
7
|
+
data.tar.gz: 85c9804583269bb39ca005273e2385dd4cf1204863bdd89100eb35699745d774389aca0ddbe570051c79a929857827f14a18498ff3f3fb1acb6165f6448d41e8
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require "concurrent-ruby"
|
|
1
2
|
require "aws-sdk-core"
|
|
2
3
|
require "aws-sdk-secretsmanager"
|
|
3
4
|
require "aws-sdk-ecs"
|
|
@@ -5,6 +6,24 @@ require "net/http"
|
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
module HerdstWorker
|
|
9
|
+
module ExpiringCredentials
|
|
10
|
+
|
|
11
|
+
attr_accessor :expiry_timestamp
|
|
12
|
+
|
|
13
|
+
def set_expiry(expiry)
|
|
14
|
+
self.expiry_timestamp = expiry
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def has_expired?
|
|
18
|
+
if self.expiry_timestamp.nil?
|
|
19
|
+
false
|
|
20
|
+
else
|
|
21
|
+
Time.now.utc.to_i > self.expiry_timestamp
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
8
27
|
module Configuration
|
|
9
28
|
class Metadata
|
|
10
29
|
|
|
@@ -22,6 +41,8 @@ module HerdstWorker
|
|
|
22
41
|
self.secrets["ENV"] = env
|
|
23
42
|
self.secret_json_keys = ["STRIPE_PLANS"]
|
|
24
43
|
|
|
44
|
+
Aws::Credentials.include HerdstWorker::ExpiringCredentials
|
|
45
|
+
|
|
25
46
|
begin
|
|
26
47
|
self.reload!
|
|
27
48
|
rescue Exception => ex
|
|
@@ -104,17 +125,32 @@ module HerdstWorker
|
|
|
104
125
|
make_request!(get_credentials_uri) :
|
|
105
126
|
self.config.config_for(:aws)
|
|
106
127
|
|
|
128
|
+
expiry_time = (Time.parse(credentials["Expiration"]).utc - 5.minutes) rescue (Time.now.utc + 1.hour)
|
|
129
|
+
|
|
130
|
+
# Set credential info
|
|
107
131
|
self.aws_credentials = Aws::Credentials.new(
|
|
108
132
|
credentials["AccessKeyId"],
|
|
109
133
|
credentials["SecretAccessKey"],
|
|
110
134
|
credentials["Token"]
|
|
111
135
|
)
|
|
112
|
-
|
|
136
|
+
self.aws_credentials.set_expiry(expiry_time.to_i)
|
|
137
|
+
|
|
138
|
+
# Set global config
|
|
113
139
|
Aws.config.update(
|
|
114
140
|
region: self.get_aws_region(credentials),
|
|
115
141
|
credentials: self.aws_credentials
|
|
116
142
|
)
|
|
117
|
-
|
|
143
|
+
|
|
144
|
+
if self.is_prod?
|
|
145
|
+
# Refresh the credentials just before the expiry time
|
|
146
|
+
expiry_in_seconds = (expiry_time - Time.now.utc).to_i
|
|
147
|
+
expiry_in_seconds = 60 if expiry_in_seconds < 60
|
|
148
|
+
|
|
149
|
+
Concurrent::ScheduledTask.execute(expiry_in_seconds) do
|
|
150
|
+
self.get_aws_credentials
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
118
154
|
self.aws_credentials
|
|
119
155
|
end
|
|
120
156
|
|
|
@@ -107,19 +107,23 @@ module HerdstWorker
|
|
|
107
107
|
self.app.logger.queue_stats.info "STATS (#{self.processor_status}): #{stats.inspect}"
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
if self.poller.client.config.credentials.has_expired?
|
|
111
|
+
self.poller.client.config.credentials = self.app.config.metadata.get_aws_credentials
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
# After hours of running terminate application.
|
|
111
115
|
# The app will automatically restart in production
|
|
112
116
|
current_time = Time.now.utc.to_i
|
|
113
117
|
if (self.processor_status == "working") && (current_time >= self.restart_time)
|
|
114
118
|
runtime = current_time - self.start_time
|
|
115
|
-
self.app.logger.queue.
|
|
119
|
+
self.app.logger.queue.warn "Stopping after #{runtime} seconds of work"
|
|
116
120
|
set_status "stopping"
|
|
117
121
|
|
|
118
122
|
# On finishing wait for jobs to complete and then set status
|
|
119
123
|
# to idle
|
|
120
124
|
elsif self.processor_status == "finishing"
|
|
121
125
|
if self.job_count == 0
|
|
122
|
-
self.app.logger.queue.
|
|
126
|
+
self.app.logger.queue.warn "Setting processor status to idle"
|
|
123
127
|
set_status "idle"
|
|
124
128
|
end
|
|
125
129
|
|
|
@@ -127,14 +131,14 @@ module HerdstWorker
|
|
|
127
131
|
# to stopped. Once stopped the polling will terminate.
|
|
128
132
|
elsif self.processor_status == "stopping"
|
|
129
133
|
if self.job_count == 0
|
|
130
|
-
self.app.logger.queue.
|
|
134
|
+
self.app.logger.queue.warn "Setting processor status to stopped"
|
|
131
135
|
set_status "stopped"
|
|
132
136
|
end
|
|
133
137
|
|
|
134
138
|
end
|
|
135
139
|
|
|
136
140
|
if self.processor_status == "stopped"
|
|
137
|
-
self.app.logger.queue.
|
|
141
|
+
self.app.logger.queue.warn "Exiting program, Service requested to stop"
|
|
138
142
|
throw :stop_polling
|
|
139
143
|
end
|
|
140
144
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: herdst_worker
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Herd.St
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|