Module: Resque::Plugins::Priority

Defined in:
lib/resque/plugins/priority.rb

Instance Method Summary collapse

Instance Method Details

#after_enqueue_set_priority(*args) ⇒ Object



26
27
28
# File 'lib/resque/plugins/priority.rb', line 26

def after_enqueue_set_priority(*args)
  Resque.redis.setnx(priority_key(*args), @priority)
end

#around_perform_retrieve_priority(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/resque/plugins/priority.rb', line 30

def around_perform_retrieve_priority(*args)
  key = priority_key(*args)
  priority = Resque.redis.get(key)
  self.priority = priority && priority.empty? ? :normal : priority

  begin
    yield
  ensure
    Resque.redis.del(key)
    @queue = @queue_without_priority
    @priority = nil
  end
end

#priority=(p) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/resque/plugins/priority.rb', line 14

def priority=(p)
  @queue_without_priority ||= @queue
  if [:high, :low].include?(p.to_sym)
    @queue = "#{@queue}_#{p}".to_sym
  end
  @priority = p.to_sym
end

#priority_key(*args) ⇒ Object



22
23
24
# File 'lib/resque/plugins/priority.rb', line 22

def priority_key(*args)
  "priority:#{name}-#{args.to_s}"
end