quebert
quebert copied to clipboard
Job priority labels
Job priorities currently live in the Jobs
class at https://github.com/polleverywhere/quebert/blob/multiple-tubes/lib/quebert/job.rb#L11-17 in a way that's specific to the Beanstalkd backend. Move priorities into something that looks like Set
that has a concept of highest
and lowest
priority. For example:
pri = Quebert::Prioties.new(%w[high medium low])
pri.highest # "high"
pri.lowest # "low"
pri.to_a # ['high', 'medium', 'low']
pri.lowest.escalate # 'low'
pri.to_a # ['high', 'low', 'medium']
pri.lowest # 'medium'
pri['high'].relative_position_between(0..2**32) # 2147483648
The backend that's using priorities can figure out the math needed to schedule a job as high or low priority based on its relative position. Beanstalkd would use 2**32
for low-priority jobs and 0
for high priority jobs.
A job would specify its priority via:
class ImportantJob < Quebert::Job
def priority
'high'
end
end
if a priority is not specified from the list of priorities in the configuration, an exception should be raised.