Class: Bluth::Gob
- Inherits:
-
Storable
- Object
- Storable
- Bluth::Gob
- Includes:
- Familia, Familia::Stamps
- Defined in:
- lib/bluth.rb
Constant Summary collapse
- MAX_ATTEMPTS =
3.freeze
Instance Method Summary collapse
- #attempt! ⇒ Object
- #attempt? ⇒ Boolean
- #clear! ⇒ Object
- #current_queue ⇒ Object
- #delayed? ⇒ Boolean
- #dequeue! ⇒ Object
- #duration ⇒ Object
- #failure!(msg = nil) ⇒ Object
- #handler ⇒ Object
- #jobid ⇒ Object
- #move!(to, msg = nil) ⇒ Object
- #perform ⇒ Object
- #preprocess ⇒ Object
- #queue ⇒ Object
- #retry!(msg = nil) ⇒ Object
- #running! ⇒ Object
- #success!(msg = nil) ⇒ Object
Instance Method Details
#attempt! ⇒ Object
308 309 310 |
# File 'lib/bluth.rb', line 308 def attempt! @attempts = attempts + 1 end |
#attempt? ⇒ Boolean
305 306 307 |
# File 'lib/bluth.rb', line 305 def attempt? attempts < MAX_ATTEMPTS end |
#clear! ⇒ Object
295 296 297 298 299 |
# File 'lib/bluth.rb', line 295 def clear! @attempts = 0 @messages = [] save end |
#current_queue ⇒ Object
311 312 313 |
# File 'lib/bluth.rb', line 311 def current_queue @current_queue end |
#delayed? ⇒ Boolean
327 328 329 330 |
# File 'lib/bluth.rb', line 327 def delayed? start = @stime || 0 start > Time.now.utc.to_f end |
#dequeue! ⇒ Object
352 353 354 355 |
# File 'lib/bluth.rb', line 352 def dequeue! Familia.ld "Deleting #{self.jobid} from #{queue.rediskey}" if Familia.debug? queue.remove 0, self.jobid end |
#duration ⇒ Object
344 345 346 347 348 |
# File 'lib/bluth.rb', line 344 def duration return 0 if @stime.nil? et = @etime || Time.now.utc.to_i et - @stime end |
#failure!(msg = nil) ⇒ Object
334 335 336 337 338 |
# File 'lib/bluth.rb', line 334 def failure!(msg=nil) @etime = Time.now.utc.to_i self.handler.failure! move! :failed, msg end |
#handler ⇒ Object
314 315 316 |
# File 'lib/bluth.rb', line 314 def handler eval "::#{@handler}" if @handler end |
#jobid ⇒ Object
292 293 294 |
# File 'lib/bluth.rb', line 292 def jobid Gibbler::Digest.new(@jobid) end |
#move!(to, msg = nil) ⇒ Object
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/bluth.rb', line 359 def move!(to, msg=nil) @thread_id = $$ #if to.to_s == current_queue.to_s # raise Bluth::Buster, "Cannot move job to the queue it's in: #{to}" #end from, to = Bluth.queue(current_queue), Bluth.queue(to) Familia.ld "Moving #{self.jobid} from #{from.rediskey} to #{to.rediskey}" if Familia.debug? @messages << msg unless msg.nil? || msg.empty? # We push first to make sure we never lose a Gob ID. Instead # there's the small chance of a job ID being in two queues. to << @jobid ret = from.remove @jobid, 0 @current_queue = to.name save # update messages end |
#perform ⇒ Object
317 318 319 320 321 322 323 324 325 326 |
# File 'lib/bluth.rb', line 317 def perform @attempts += 1 Familia.ld "PERFORM: #{self.to_hash.inspect}" if Familia.debug? @stime = Time.now.utc.to_f save # update the time self.handler.prepare if self.class.respond_to?(:prepare) self.handler.perform @data @etime = Time.now.utc.to_f save # update the time end |
#preprocess ⇒ Object
300 301 302 303 304 |
# File 'lib/bluth.rb', line 300 def preprocess @attempts ||= 0 @messages ||= [] @create_time ||= Time.now.utc.to_f end |
#queue ⇒ Object
349 350 351 |
# File 'lib/bluth.rb', line 349 def queue Bluth.queue(current_queue) end |
#retry!(msg = nil) ⇒ Object
331 332 333 |
# File 'lib/bluth.rb', line 331 def retry!(msg=nil) move! :high, msg end |
#running! ⇒ Object
356 357 358 |
# File 'lib/bluth.rb', line 356 def running! move! :running end |
#success!(msg = nil) ⇒ Object
339 340 341 342 343 |
# File 'lib/bluth.rb', line 339 def success!(msg=nil) @etime = Time.now.utc.to_i self.handler.success! move! :successful, msg end |