Module: Resque::Integration::Priority

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

Overview

Public: job with priority queues

Examples:

class MyJob
  include Resque::Integration

  queue :foo
  prioritized

  def self.perform(arg)
    heavy_lifting_work
  end
end

MyJob.enqueue_with_priority(:high, 1, another_param: 2) # enqueue job to :foo_high queue
MyJob.enqueue_with_priority(:low, 1, another_param: 2) # enqueue job to :foo_low queue

class MyUniqueJob
  include Resque::Integration

  queue :foo
  unique
  prioritized

  def self.execute(*args)
    meta = get_meta

    heavy_lifting_work do
      meta[:count] += 1
    end
  end
end

Defined Under Namespace

Modules: Overrides

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



36
37
38
# File 'lib/resque/integration/priority.rb', line 36

def self.extended(base)
  base.singleton_class.prepend(Overrides)
end

Instance Method Details

#enqueue_with_priority(priority, *args) ⇒ Object

Public: enqueue job to priority queue

Example:

MyJob.enqueue_with_priority(:high, 1)


74
75
76
77
78
79
80
81
82
# File 'lib/resque/integration/priority.rb', line 74

def enqueue_with_priority(priority, *args)
  queue = priority_queue(priority)

  if unique?
    enqueue_to(queue, *args, priority)
  else
    Resque.enqueue_to(queue, self, *args, priority)
  end
end

#priority?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/resque/integration/priority.rb', line 66

def priority?
  true
end

#priority_queue(priority) ⇒ Object



84
85
86
# File 'lib/resque/integration/priority.rb', line 84

def priority_queue(priority)
  priority.to_sym == :normal ? queue : "#{queue}_#{priority}".to_sym
end