herdst_worker 0.2.20 → 0.2.22
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/bin/herdst_worker +11 -1
- data/bin/herdst_worker_console +1 -1
- data/bin/herdst_worker_health +2 -2
- data/lib/herdst_worker/application/facade.rb +10 -25
- data/lib/herdst_worker/queue/facade.rb +4 -8
- data/lib/herdst_worker/queue/processor.rb +49 -69
- data/lib/herdst_worker/version.rb +1 -1
- metadata +1 -2
- data/lib/herdst_worker/signals/facade.rb +0 -35
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7df01a32a23f6963c2b6a6f080aa917ef9d33c3dc72928f28f8162d86f4f42db
|
|
4
|
+
data.tar.gz: d222ec3faf7a24c0b5d73b905c384356635d6061104a7724dc84186588f81609
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b2a5d21ad826cab67bf3c78bbcdf4be85bca917ea0c79475bedbc073d47ad5b9d5d9b6ec4b1b713005711f552d0d571c643c36e88197c9e3e7fa0aef6b0c411
|
|
7
|
+
data.tar.gz: be88aa8b2fbd5a004832a90ba992dfdd8c3108059d1fdaf34017242fb3c09c1a8d39213e3e6f7d3249b5919876245ef30371a5aa9dfa73b438d9de4c6858f870
|
data/bin/herdst_worker
CHANGED
|
@@ -11,6 +11,16 @@ application_file = arg_pair["application"] || "application.rb"
|
|
|
11
11
|
application_path = "#{Dir.pwd}/#{application_file}"
|
|
12
12
|
application_env = arg_pair["env"] || "production"
|
|
13
13
|
queue_enabled = arg_pair["queue_enabled"] == "false" ? false : true
|
|
14
|
+
primary_process = true
|
|
15
|
+
runtime = ((3600 * 4.75) + (rand * (3600 * 0.25))).floor # Between 4.75 hours and 5 hours
|
|
16
|
+
|
|
17
|
+
if arg_pair["primary"].to_s == "false"
|
|
18
|
+
primary_process = false
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
if arg_pair["runtime"]
|
|
22
|
+
runtime = arg_pair["runtime"].to_i || runtime
|
|
23
|
+
end
|
|
14
24
|
|
|
15
25
|
raise "Please specify a name for the application E.g. --name=[name]" unless application_name
|
|
16
26
|
raise "Please specify a family for the application E.g. --family=[family]" unless application_family
|
|
@@ -21,7 +31,7 @@ ENV["RAILS_ENV"] = application_env
|
|
|
21
31
|
|
|
22
32
|
require_relative "../lib/herdst_worker"
|
|
23
33
|
|
|
24
|
-
application_instance = HerdstWorker::Application.new(application_env, application_name, application_family, queue_enabled)
|
|
34
|
+
application_instance = HerdstWorker::Application.new(application_env, application_name, application_family, queue_enabled, primary_process, runtime)
|
|
25
35
|
|
|
26
36
|
require_relative application_path
|
|
27
37
|
|
data/bin/herdst_worker_console
CHANGED
|
@@ -22,7 +22,7 @@ require "irb"
|
|
|
22
22
|
require "irb/completion"
|
|
23
23
|
require_relative "../lib/herdst_worker"
|
|
24
24
|
|
|
25
|
-
application_instance = HerdstWorker::Application.new(application_env, application_name, application_family, false)
|
|
25
|
+
application_instance = HerdstWorker::Application.new(application_env, application_name, application_family, false, false, 0)
|
|
26
26
|
|
|
27
27
|
require_relative application_path
|
|
28
28
|
|
data/bin/herdst_worker_health
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
tmp_path = Dir.pwd + "/tmp"
|
|
4
|
-
process_id = File.new(tmp_path + "/process_id").read rescue nil
|
|
5
|
-
process_status = File.new(tmp_path + "/process_status").read rescue nil
|
|
4
|
+
process_id = File.new(tmp_path + "/process_id").read.strip rescue nil
|
|
5
|
+
process_status = File.new(tmp_path + "/process_status").read.strip rescue nil
|
|
6
6
|
unhealthy = process_id == nil || ["stopped"].include?(process_status)
|
|
7
7
|
|
|
8
8
|
Kernel.exit(unhealthy ? 1 : 0)
|
|
@@ -4,7 +4,6 @@ require "aws-sdk-ecs"
|
|
|
4
4
|
require_relative '../configuration/facade'
|
|
5
5
|
require_relative '../log/facade'
|
|
6
6
|
require_relative '../autoload/facade'
|
|
7
|
-
require_relative '../signals/facade'
|
|
8
7
|
require_relative '../queue/facade'
|
|
9
8
|
require_relative '../adapters/facade'
|
|
10
9
|
|
|
@@ -15,13 +14,14 @@ module HerdstWorker
|
|
|
15
14
|
|
|
16
15
|
attr_accessor :name, :family
|
|
17
16
|
attr_accessor :logger, :config, :autoload
|
|
18
|
-
attr_accessor :poller_enabled, :queues, :poller_url, :queue
|
|
17
|
+
attr_accessor :poller_enabled, :queues, :poller_url, :queue, :primary_process, :runtime
|
|
19
18
|
|
|
20
19
|
|
|
21
|
-
def initialize(env, name, family, poller_enabled)
|
|
20
|
+
def initialize(env, name, family, poller_enabled, primary_process, runtime)
|
|
22
21
|
self.name = name
|
|
23
22
|
self.family = family
|
|
24
23
|
self.poller_enabled = poller_enabled
|
|
24
|
+
self.runtime = runtime
|
|
25
25
|
self.queues = ActiveSupport::HashWithIndifferentAccess.new
|
|
26
26
|
|
|
27
27
|
HerdstWorker.set_application(self)
|
|
@@ -44,7 +44,7 @@ module HerdstWorker
|
|
|
44
44
|
|
|
45
45
|
def get_queue(name)
|
|
46
46
|
if self.queues[name]
|
|
47
|
-
HerdstWorker::Queue::Facade.new(self, false, self.queues[name], 20)
|
|
47
|
+
HerdstWorker::Queue::Facade.new(self, false, 0, self.queues[name], 20)
|
|
48
48
|
else
|
|
49
49
|
nil
|
|
50
50
|
end
|
|
@@ -61,9 +61,7 @@ module HerdstWorker
|
|
|
61
61
|
if self.queue == nil
|
|
62
62
|
self.logger.info "Starting Application (#{$$})"
|
|
63
63
|
|
|
64
|
-
HerdstWorker::
|
|
65
|
-
|
|
66
|
-
self.queue = HerdstWorker::Queue::Facade.new(self, self.poller_enabled, self.poller_url, 20)
|
|
64
|
+
self.queue = HerdstWorker::Queue::Facade.new(self, self.poller_enabled, self.runtime, self.poller_url, 20)
|
|
67
65
|
self.queue.start
|
|
68
66
|
end
|
|
69
67
|
end
|
|
@@ -91,24 +89,11 @@ module HerdstWorker
|
|
|
91
89
|
|
|
92
90
|
|
|
93
91
|
def register_new_task
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
# )
|
|
100
|
-
|
|
101
|
-
# resp = ecs_client.update_service({
|
|
102
|
-
# :cluster => info[:cluster],
|
|
103
|
-
# :service => info[:service_name],
|
|
104
|
-
|
|
105
|
-
# # :task_definition => "amazon-ecs-sample",
|
|
106
|
-
|
|
107
|
-
# :desired_count => desired_count,
|
|
108
|
-
# })
|
|
109
|
-
|
|
110
|
-
# puts "info"
|
|
111
|
-
# puts info.inspect
|
|
92
|
+
if self.primary_process
|
|
93
|
+
self.queue.stop
|
|
94
|
+
else
|
|
95
|
+
self.queue.stop
|
|
96
|
+
end
|
|
112
97
|
end
|
|
113
98
|
|
|
114
99
|
|
|
@@ -7,12 +7,13 @@ module HerdstWorker
|
|
|
7
7
|
class Facade
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
attr_accessor :app, :enabled, :url, :queue_wait_time, :processor
|
|
10
|
+
attr_accessor :app, :enabled, :runtime, :url, :queue_wait_time, :processor
|
|
11
11
|
|
|
12
12
|
|
|
13
|
-
def initialize(app, enabled, url, queue_wait_time)
|
|
13
|
+
def initialize(app, enabled, runtime, url, queue_wait_time)
|
|
14
14
|
self.app = app
|
|
15
15
|
self.enabled = enabled
|
|
16
|
+
self.runtime = runtime
|
|
16
17
|
self.url = url
|
|
17
18
|
self.queue_wait_time = queue_wait_time
|
|
18
19
|
end
|
|
@@ -28,11 +29,6 @@ module HerdstWorker
|
|
|
28
29
|
end
|
|
29
30
|
|
|
30
31
|
|
|
31
|
-
def halt
|
|
32
|
-
self.get_processor.halt
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
|
|
36
32
|
def stop
|
|
37
33
|
self.get_processor.stop
|
|
38
34
|
end
|
|
@@ -40,7 +36,7 @@ module HerdstWorker
|
|
|
40
36
|
|
|
41
37
|
def get_processor
|
|
42
38
|
unless self.processor
|
|
43
|
-
self.processor = HerdstWorker::Queue::Processor.new(app, self.enabled, self.url, self.queue_wait_time)
|
|
39
|
+
self.processor = HerdstWorker::Queue::Processor.new(app, self.enabled, self.runtime, self.url, self.queue_wait_time)
|
|
44
40
|
end
|
|
45
41
|
|
|
46
42
|
self.processor
|
|
@@ -9,12 +9,12 @@ module HerdstWorker
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
attr_accessor :app, :enabled, :queue_url, :queue_wait_time, :poller
|
|
12
|
-
attr_accessor :start_time, :
|
|
13
|
-
attr_accessor :processor_status, :job_count, :max_jobs
|
|
12
|
+
attr_accessor :start_time, :run_duration, :expire_at
|
|
13
|
+
attr_accessor :processor_status, :processor_expired, :job_count, :max_jobs
|
|
14
14
|
attr_accessor :attempt_threshold, :visibility_timeout, :ignored_notifications
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def initialize(app, enabled, queue_url, queue_wait_time)
|
|
17
|
+
def initialize(app, enabled, runtime, queue_url, queue_wait_time)
|
|
18
18
|
self.app = app
|
|
19
19
|
self.enabled = enabled
|
|
20
20
|
self.queue_url = queue_url
|
|
@@ -27,12 +27,12 @@ module HerdstWorker
|
|
|
27
27
|
self.ignored_notifications = [
|
|
28
28
|
"AmazonSnsSubscriptionSucceeded"
|
|
29
29
|
]
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
self.
|
|
33
|
-
self.
|
|
30
|
+
|
|
31
|
+
self.processor_status = "starting"
|
|
32
|
+
self.processor_expired = false
|
|
33
|
+
self.run_duration = runtime
|
|
34
34
|
self.reset_time
|
|
35
|
-
|
|
35
|
+
|
|
36
36
|
# Start the processor as working
|
|
37
37
|
self.set_status "starting"
|
|
38
38
|
|
|
@@ -49,7 +49,7 @@ module HerdstWorker
|
|
|
49
49
|
self.poller.poll(:wait_time_seconds => self.queue_wait_time, :skip_delete => false) do |msg|
|
|
50
50
|
process_message(msg)
|
|
51
51
|
end
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
self.app.deregister_task
|
|
54
54
|
else
|
|
55
55
|
raise "Cannot start a queue which is not enabled"
|
|
@@ -72,14 +72,6 @@ module HerdstWorker
|
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
|
|
75
|
-
# Sets the processor status to finishing. The sqs before action will
|
|
76
|
-
# take care of setting the idle state once all jobs have finished.
|
|
77
|
-
def halt
|
|
78
|
-
return if self.processor_status == "finishing"
|
|
79
|
-
set_status "finishing"
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
|
|
83
75
|
# Sets the processor status to stopping. The sqs before action will
|
|
84
76
|
# take care of stopping the application once all jobs have finished.
|
|
85
77
|
def stop
|
|
@@ -118,23 +110,11 @@ module HerdstWorker
|
|
|
118
110
|
# After hours of running terminate application.
|
|
119
111
|
# The app will automatically restart in production
|
|
120
112
|
current_time = Time.now.utc.to_i
|
|
121
|
-
|
|
122
|
-
if (self.processor_status == "
|
|
123
|
-
self.
|
|
124
|
-
|
|
125
|
-
elsif (self.processor_status == "working") && (current_time >= self.stop_processing_at)
|
|
113
|
+
|
|
114
|
+
if (self.processor_status == "working") && (current_time >= self.expire_at) && (self.processor_expired == false)
|
|
115
|
+
self.processor_expired = true
|
|
126
116
|
self.app.force_stop(900)
|
|
127
117
|
self.app.register_new_task
|
|
128
|
-
|
|
129
|
-
set_status "stopping"
|
|
130
|
-
|
|
131
|
-
# On finishing wait for jobs to complete and then set status to idle
|
|
132
|
-
elsif self.processor_status == "finishing"
|
|
133
|
-
if self.job_count == 0
|
|
134
|
-
self.app.logger.queue.warn "Setting processor status to idle"
|
|
135
|
-
set_status "idle"
|
|
136
|
-
end
|
|
137
|
-
|
|
138
118
|
end
|
|
139
119
|
|
|
140
120
|
# On stopping wait for jobs to complete and then set status
|
|
@@ -181,50 +161,51 @@ module HerdstWorker
|
|
|
181
161
|
self.job_count -= 1
|
|
182
162
|
|
|
183
163
|
}.rescue { |ex|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
164
|
+
begin
|
|
165
|
+
if will_fail_permanently
|
|
166
|
+
self.app.logger.queue.error "Message failed #{attempt_number} times, Reporting and failing permanently. \n#{ex.to_s} \n#{ex.backtrace.join("\n")}"
|
|
167
|
+
Sentry.capture_exception(ex, {
|
|
168
|
+
:level => "fatal",
|
|
169
|
+
:extra => {
|
|
170
|
+
"queue_attempts" => attempt_number,
|
|
171
|
+
"queue_message_body" => msg.body
|
|
172
|
+
}
|
|
173
|
+
})
|
|
193
174
|
|
|
194
|
-
|
|
195
|
-
|
|
175
|
+
else
|
|
176
|
+
self.app.logger.queue.error "Message failed #{attempt_number} times, Adding back to queue."
|
|
177
|
+
|
|
178
|
+
self.poller.client.send_message({
|
|
179
|
+
:queue_url => self.poller.queue_url,
|
|
180
|
+
:message_body => msg.body,
|
|
181
|
+
:delay_seconds => self.visibility_timeout,
|
|
182
|
+
:message_attributes => msg_attrs.merge({
|
|
183
|
+
"attempts" => {
|
|
184
|
+
:string_value => attempt_number.to_s,
|
|
185
|
+
:data_type => "Number"
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
})
|
|
189
|
+
end
|
|
196
190
|
|
|
197
191
|
if self.app.config.is_dev?
|
|
198
|
-
|
|
199
|
-
|
|
192
|
+
self.app.logger.queue.error "Processor Error:"
|
|
193
|
+
self.app.logger.queue.error ex.message
|
|
194
|
+
self.app.logger.queue.error ex.backtrace
|
|
200
195
|
end
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
:string_value => attempt_number.to_s,
|
|
209
|
-
:data_type => "Number"
|
|
210
|
-
}
|
|
211
|
-
})
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
self.poller.client.send_message replaced_message
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
if self.app.config.is_dev?
|
|
218
|
-
self.app.logger.queue.error "Processor Error:"
|
|
219
|
-
self.app.logger.queue.error ex.message
|
|
220
|
-
self.app.logger.queue.error ex.backtrace
|
|
196
|
+
|
|
197
|
+
rescue Exception => inner_ex
|
|
198
|
+
self.app.logger.queue.error inner_ex.message
|
|
199
|
+
|
|
200
|
+
ensure
|
|
201
|
+
self.job_count -= 1
|
|
202
|
+
|
|
221
203
|
end
|
|
222
|
-
|
|
223
|
-
self.job_count -= 1
|
|
224
204
|
}.execute
|
|
225
205
|
else
|
|
226
206
|
self.poller.change_message_visibility_timeout(msg, 5)
|
|
227
207
|
throw :skip_delete
|
|
208
|
+
|
|
228
209
|
end
|
|
229
210
|
end
|
|
230
211
|
|
|
@@ -232,8 +213,7 @@ module HerdstWorker
|
|
|
232
213
|
private
|
|
233
214
|
def reset_time
|
|
234
215
|
self.start_time = Time.now.utc.to_i
|
|
235
|
-
self.
|
|
236
|
-
self.stop_at = self.stop_processing_at + self.stop_suration
|
|
216
|
+
self.expire_at = self.start_time + self.run_duration
|
|
237
217
|
end
|
|
238
218
|
|
|
239
219
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.22
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Herd.St
|
|
@@ -262,7 +262,6 @@ files:
|
|
|
262
262
|
- lib/herdst_worker/queue/facade.rb
|
|
263
263
|
- lib/herdst_worker/queue/processor.rb
|
|
264
264
|
- lib/herdst_worker/queue/runner.rb
|
|
265
|
-
- lib/herdst_worker/signals/facade.rb
|
|
266
265
|
- lib/herdst_worker/version.rb
|
|
267
266
|
homepage: https://herd.st
|
|
268
267
|
licenses:
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
module HerdstWorker
|
|
2
|
-
module Signals
|
|
3
|
-
class Facade
|
|
4
|
-
|
|
5
|
-
def self.listen(process_path)
|
|
6
|
-
write_process_file(process_path)
|
|
7
|
-
|
|
8
|
-
# Start
|
|
9
|
-
Signal.trap "USR1" do |x|
|
|
10
|
-
HerdstWorker::Queue::Facade.start
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# Halt
|
|
14
|
-
Signal.trap "USR2" do |x|
|
|
15
|
-
HerdstWorker::Queue::Facade.halt
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# Stop (abort)
|
|
19
|
-
Signal.trap "ABRT" do |x|
|
|
20
|
-
HerdstWorker::Queue::Facade.stop
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
def self.write_process_file(process_path)
|
|
26
|
-
# Write process id to file so we can signal the current process
|
|
27
|
-
process_id = "#{$$}"
|
|
28
|
-
process_file = process_path + "/process_id"
|
|
29
|
-
|
|
30
|
-
File.open(process_file, "w") { |file| file.write(process_id) }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|