Class: Bluth::Worker
- Inherits:
-
Storable
- Object
- Storable
- Bluth::Worker
- Includes:
- WorkerBase, Daemonizable, Familia, Familia::Stamps, Logging
- Defined in:
- lib/bluth/worker.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.interval ⇒ Object
Returns the value of attribute interval.
Attributes included from Daemonizable
Instance Method Summary collapse
Methods included from Daemonizable
#change_privilege, #daemonize, included, #on_restart, #pid, #restart
Methods included from Logging
#debug, debug, debug?, #log, log, #log_error, log_error, #silent, #silent=, silent?, #trace, trace, trace?
Methods included from WorkerBase
#current_job, included, #init, #kill, #name, #wid, #working!
Class Attribute Details
.interval ⇒ Object
Returns the value of attribute interval.
118 119 120 |
# File 'lib/bluth/worker.rb', line 118 def interval @interval end |
Instance Method Details
#run ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/bluth/worker.rb', line 164 def run begin @process_id = $$ scheduler = Rufus::Scheduler.start_new Bluth.connect self.class.runblock :onstart Familia.info "Setting interval: #{Worker.interval} sec (queuetimeout: #{Bluth.queuetimeout})" Familia.reconnect_all! # Need to reconnect after daemonize save scheduler.every Worker.interval, :blocking => true do |task| Familia.ld "#{$$} TICK @ #{Time.now.utc}" sleep rand find_gob task end scheduler.join rescue => ex msg = "#{ex.class}: #{ex.}" Familia.info msg Familia.trace :EXCEPTION, msg, caller[1] if Familia.debug? self.class.runblock :onexit destroy! rescue Interrupt => ex puts <<-EOS.gsub(/(?:^|\n)\s*/, "\n") Exiting... (You may need to wait up to #{Bluth.queuetimeout} seconds for this worker to exit cleanly.) EOS # We reconnect to the queue in case we're currently # waiting on a brpop (blocking pop) timeout. self.class.runblock :onexit destroy! end end |
#run! ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/bluth/worker.rb', line 146 def run! begin Bluth.connect self.class.runblock :onstart find_gob rescue => ex msg = "#{ex.class}: #{ex.}" Familia.info msg Familia.trace :EXCEPTION, msg, caller[1] if Familia.debug? self.class.runblock :onexit destroy! rescue Interrupt => ex puts $/, "Exiting..." self.class.runblock :onexit destroy! end end |