Module: Resque::Additions

Defined in:
lib/resque/additions.rb

Instance Method Summary collapse

Instance Method Details

#dequeue_from(queue, klass, *args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/resque/additions.rb', line 3

def dequeue_from(queue, klass, *args)
  ####### ------ Resque Job --------
  # Perform before_dequeue hooks. Don't perform dequeue if any hook returns false
  before_hooks = Plugin.before_dequeue_hooks(klass).collect do |hook|
    klass.send(hook, *args)
  end
  return if before_hooks.any? { |result| result == false }

  destroyed = Job.destroy(queue, klass, *args)

  Plugin.after_dequeue_hooks(klass).each do |hook|
    klass.send(hook, *args)
  end

  destroyed
end

#remove_delayed_job_with_queue_from_timestamp(timestamp, queue, klass, *args) ⇒ Object

Given a timestamp and job (klass + args) it removes all instances and returns the count of jobs removed.

O(N) where N is the number of jobs scheduled to fire at the given timestamp



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/resque/additions.rb', line 40

def remove_delayed_job_with_queue_from_timestamp(timestamp, queue, klass, *args)
  return 0 if Resque.inline?

  key = "delayed:#{timestamp.to_i}"
  encoded_job = encode(job_to_hash_with_queue(queue, klass, args))

  redis.srem("timestamps:#{encoded_job}", key)
  count = redis.lrem(key, 0, encoded_job)
  clean_up_timestamp(key, timestamp)

  count
end

#remove_delayed_with_queue(queue, klass, *args) ⇒ Object

Given an encoded item, remove it from the delayed_queue



30
31
32
33
# File 'lib/resque/additions.rb', line 30

def remove_delayed_with_queue(queue, klass, *args)
  search = encode(job_to_hash_with_queue(queue,klass, args))
  remove_delayed_job(search)
end

#scheduled_at_with_queue(queue, klass, *args) ⇒ Object

—— Resque Delayed Job ——– Returns delayed jobs schedule timestamp for klass, args.



22
23
24
25
26
27
# File 'lib/resque/additions.rb', line 22

def scheduled_at_with_queue(queue, klass, *args)
  search = encode(job_to_hash_with_queue(queue,klass, args))
  redis.smembers("timestamps:#{search}").map do |key|
    key.tr('delayed:', '').to_i
  end
end