herdst_worker 0.2.15 → 0.2.17
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/lib/herdst_worker/application/facade.rb +9 -0
- data/lib/herdst_worker/queue/processor.rb +16 -9
- data/lib/herdst_worker/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 38eaf100a0f45339a420402ba0dd782cf4daa2338fe6f362c65a35dade5f3be9
|
|
4
|
+
data.tar.gz: d07205a7ea5857f3fe4b1906526cc87043bbe28668613bd1c7e472f08480251e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 44cfd9d0daca7cf3baf25f38f556c2fa3b1590edc111dfff3b1ab65b1db7aac02e62448f9afea1b7da97d0c41bc5ad7fa4c64fe8c7aa5135dccf98345e5f9199
|
|
7
|
+
data.tar.gz: e1d21d8ab1e447768bc2453b724594c71e27daedff5d11333b658bc7d19c4db58b2f0b8f872b967e41d1cac68dbefb5bbd56fa0493441ca9a4a4fb27344affe8
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require "concurrent-ruby"
|
|
2
|
+
|
|
1
3
|
require_relative '../configuration/facade'
|
|
2
4
|
require_relative '../log/facade'
|
|
3
5
|
require_relative '../autoload/facade'
|
|
@@ -64,6 +66,13 @@ module HerdstWorker
|
|
|
64
66
|
self.queue.start
|
|
65
67
|
end
|
|
66
68
|
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def stop(exit_code = 0)
|
|
72
|
+
self.logger.warn "Application exiting (#{exit_code})"
|
|
73
|
+
|
|
74
|
+
Kernel.exit(exit_code)
|
|
75
|
+
end
|
|
67
76
|
|
|
68
77
|
|
|
69
78
|
def config_for(name)
|
|
@@ -9,7 +9,7 @@ module HerdstWorker
|
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
attr_accessor :app, :enabled, :queue_url, :queue_wait_time, :poller
|
|
12
|
-
attr_accessor :start_time, :restart_time
|
|
12
|
+
attr_accessor :start_time, :restart_time, :run_time
|
|
13
13
|
attr_accessor :processor_status, :job_count, :max_jobs
|
|
14
14
|
attr_accessor :attempt_threshold, :visibility_timeout, :ignored_notifications
|
|
15
15
|
|
|
@@ -29,6 +29,7 @@ module HerdstWorker
|
|
|
29
29
|
]
|
|
30
30
|
|
|
31
31
|
# Set the start time
|
|
32
|
+
self.run_time = (3600 * 4) + (rand * 600).floor # Four hours + bit more (< 10 minutes)
|
|
32
33
|
self.reset_time
|
|
33
34
|
|
|
34
35
|
# Start the processor as working
|
|
@@ -47,6 +48,10 @@ module HerdstWorker
|
|
|
47
48
|
self.poller.poll(:wait_time_seconds => self.queue_wait_time, :skip_delete => false) do |msg|
|
|
48
49
|
process_message(msg)
|
|
49
50
|
end
|
|
51
|
+
|
|
52
|
+
if self.processor_status == "stopped"
|
|
53
|
+
self.app.stop(0)
|
|
54
|
+
end
|
|
50
55
|
else
|
|
51
56
|
raise "Cannot start a queue which is not enabled"
|
|
52
57
|
end
|
|
@@ -116,30 +121,32 @@ module HerdstWorker
|
|
|
116
121
|
current_time = Time.now.utc.to_i
|
|
117
122
|
if (self.processor_status == "working") && (current_time >= self.restart_time)
|
|
118
123
|
runtime = current_time - self.start_time
|
|
119
|
-
self.app.logger.queue.warn "
|
|
124
|
+
self.app.logger.queue.warn "Preparing to stop after #{runtime} seconds of work"
|
|
120
125
|
set_status "stopping"
|
|
121
126
|
|
|
122
|
-
# On finishing wait for jobs to complete and then set status
|
|
123
|
-
# to idle
|
|
127
|
+
# On finishing wait for jobs to complete and then set status to idle
|
|
124
128
|
elsif self.processor_status == "finishing"
|
|
125
129
|
if self.job_count == 0
|
|
126
130
|
self.app.logger.queue.warn "Setting processor status to idle"
|
|
127
131
|
set_status "idle"
|
|
128
132
|
end
|
|
129
133
|
|
|
134
|
+
end
|
|
135
|
+
|
|
130
136
|
# On stopping wait for jobs to complete and then set status
|
|
131
137
|
# to stopped. Once stopped the polling will terminate.
|
|
132
|
-
|
|
138
|
+
if self.processor_status == "stopping"
|
|
133
139
|
if self.job_count == 0
|
|
134
140
|
self.app.logger.queue.warn "Setting processor status to stopped"
|
|
135
141
|
set_status "stopped"
|
|
136
142
|
end
|
|
137
|
-
|
|
138
143
|
end
|
|
139
144
|
|
|
145
|
+
# Once stopped exit the application
|
|
140
146
|
if self.processor_status == "stopped"
|
|
141
|
-
self.app.logger.queue.warn "
|
|
142
|
-
|
|
147
|
+
self.app.logger.queue.warn "Stopping polling, Service requested to stop"
|
|
148
|
+
|
|
149
|
+
throw :stop_polling
|
|
143
150
|
end
|
|
144
151
|
end
|
|
145
152
|
|
|
@@ -221,7 +228,7 @@ module HerdstWorker
|
|
|
221
228
|
private
|
|
222
229
|
def reset_time
|
|
223
230
|
self.start_time = Time.now.utc.to_i
|
|
224
|
-
self.restart_time = self.start_time +
|
|
231
|
+
self.restart_time = self.start_time + self.run_time
|
|
225
232
|
end
|
|
226
233
|
|
|
227
234
|
end
|