Class: Updater::ThreadWorker
- Inherits:
-
Object
- Object
- Updater::ThreadWorker
- Defined in:
- lib/updater/thread_worker.rb
Overview
This class repeatedly searches the database for active jobs and runs them
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pid ⇒ Object
Returns the value of attribute pid.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ ThreadWorker
constructor
A new instance of ThreadWorker.
- #run_loop ⇒ Object
- #say(text) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ThreadWorker
Returns a new instance of ThreadWorker.
14 15 16 17 18 |
# File 'lib/updater/thread_worker.rb', line 14 def initialize(={}) @quiet = [:quiet] @name = [:name] || "host:#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}" @pid = Process.pid end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
12 13 14 |
# File 'lib/updater/thread_worker.rb', line 12 def logger @logger end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/updater/thread_worker.rb', line 11 def name @name end |
#pid ⇒ Object
Returns the value of attribute pid.
10 11 12 |
# File 'lib/updater/thread_worker.rb', line 10 def pid @pid end |
Instance Method Details
#run_loop ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/updater/thread_worker.rb', line 48 def run_loop if @t.alive? @t.wakeup #calling run here is a Bad Idea else say " ~~ Restarting Job Loop" @t = run_job_loop end end |
#say(text) ⇒ Object
38 39 40 41 |
# File 'lib/updater/thread_worker.rb', line 38 def say(text) puts text unless @quiet logger.info text if logger end |
#start ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/updater/thread_worker.rb', line 20 def start say "*** Starting job worker #{@name}" @t = run_job_loop trap('TERM') { terminate_with @t } trap('INT') { terminate_with @t } trap('USR1') do old_proc = trap('USR1','IGNORE') run_loop trap('USR1',old_proc) end Thread.pass sleep unless $exit end |
#stop ⇒ Object
43 44 45 46 |
# File 'lib/updater/thread_worker.rb', line 43 def stop raise RuntimeError unless @t terminate_with @t end |