Module: Resque::Delayed

Defined in:
lib/resque/delayed.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



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

def self.extended(base)
  base.class_eval { @delayed_queues = [] }
end

Instance Method Details

#delayed_job?(klass) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
# File 'lib/resque/delayed.rb', line 31

def delayed_job?(klass)
  klass.instance_variable_get(:@delayed) ||
    (klass.respond_to?(:delayed) and klass.delayed)
end

#delayed_queue?(queue) ⇒ Boolean

Returns:

  • (Boolean)


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

def delayed_queue?(queue)
  @delayed_queues.include? namespace_queue(queue)
end

#delayed_size(queue) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/resque/delayed.rb', line 48

def delayed_size(queue)
  queue = namespace_queue(queue)
  if delayed_queue? queue
    mongo[queue].find({'delay_until' => { '$gt' => Time.now }}).count
  else
    mongo[queue].count
  end
end

#enable_delay(queue) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/resque/delayed.rb', line 40

def enable_delay(queue)
  queue = namespace_queue(queue)
  unless delayed_queue? queue
    @delayed_queues << queue
    mongo_stats.update({:stat => 'Delayed Queues'}, {'$addToSet' => {'value' => queue}}, {:upsert => true})
  end
end

#initialize_delayedObject



26
27
28
29
# File 'lib/resque/delayed.rb', line 26

def initialize_delayed
  delayed_queues = mongo_stats.find_one(:stat => 'Delayed Queues')
  @delayed_queues = delayed_queues['value'] if delayed_queues
end

#ready_size(queue) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/resque/delayed.rb', line 57

def ready_size(queue)
  queue = namespace_queue(queue)
  if delayed_queue? queue
    mongo[queue].find({'delay_until' => { '$lt' => Time.now }}).count
  else
    mongo[queue].count
  end
end