Class: Edamame::Broker

Inherits:
PersistentQueue show all
Defined in:
lib/edamame.rb

Constant Summary

Constants inherited from PersistentQueue

PersistentQueue::DEFAULT_CONFIG

Instance Attribute Summary

Attributes inherited from PersistentQueue

#queue, #store, #tube

Instance Method Summary collapse

Methods inherited from PersistentQueue

#<<, #bury, #delete, #each, #get, #initialize, #load, #put, #release, #reserve, #stats

Constructor Details

This class inherits a constructor from Edamame::PersistentQueue

Instance Method Details

#log_job(job, *stuff) ⇒ Object



164
165
166
# File 'lib/edamame.rb', line 164

def log_job job, *stuff
  log [job.tube, job.priority, job.delay, job.obj['key'], *stuff].flatten.join("\t")
end

#reschedule(job) ⇒ Object



154
155
156
157
158
159
160
161
162
163
# File 'lib/edamame.rb', line 154

def reschedule job
  delay = job.scheduling.delay
  if delay
    # log_job job, 'rescheduled', delay, (Time.now + delay).to_flat, job.scheduling.to_flat.join
    release job
  else
    # log_job job, 'deleted'
    delete job
  end
end

#work(timeout = 10, &block) ⇒ Object



167
168
169
170
171
172
173
174
# File 'lib/edamame.rb', line 167

def work timeout=10, &block
  loop do
    job    = reserve(timeout) or break
    result = block.call(job)
    job.update!
    reschedule job
  end
end