Module: Resque::Plugins::Priority

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

Instance Method Summary collapse

Instance Method Details

#after_enqueue_set_priority(*args) ⇒ Object



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

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

#around_perform_retrieve_priority(*args) ⇒ Object



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

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)
  end
end

#priority=(p) ⇒ Object



15
16
17
# File 'lib/resque/plugins/priority.rb', line 15

def priority=(p)
  @priority = p.to_sym
end

#priority_identifier(*args) ⇒ Object



19
20
21
# File 'lib/resque/plugins/priority.rb', line 19

def priority_identifier(*args)
  args.join('-')
end

#priority_key(*args) ⇒ Object



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

def priority_key(*args)
  ['priority', name, priority_identifier(*args)].compact.join(':')
end