bin/jflow_worker in jflow-0.2.5 vs bin/jflow_worker in jflow-0.2.6
- old
+ new
@@ -36,8 +36,33 @@
JFlow::Activity::Worker.new(domain, tasklist)
.start!
end
end
-threads.each { |thr| thr.join }
+def shutdown(threads)
+ JFlow.configuration.logger.info "Sending kill signal to running threads. Please wait for current polling to finish"
+ kill_threads = []
+ threads.each do |thread|
+ thread["do_exit"] = true
+ if thread["state"] == :working
+ kill_threads << Thread.new do
+ sleep 60
+ if thread.alive?
+ thread.raise("Workers are going down!")
+ end
+ end
+ end
+ end
+ kill_threads.each { |thr| thr.join }
+end
+Signal.trap("INT") {
+ shutdown(threads)
+}
+
+# Trap `Kill `
+Signal.trap("TERM") {
+ shutdown(threads)
+}
+
+threads.each { |thr| thr.join }