Module: Resque::Plugins::SerialQueues

Extended by:
SerialQueues
Included in:
SerialQueues
Defined in:
lib/resque-serial-queues/version.rb,
lib/resque/plugins/serial_queues.rb,
lib/resque/plugins/serial_queues/config.rb

Defined Under Namespace

Classes: Config

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.is_queue_locked?(queue) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/resque/plugins/serial_queues.rb', line 20

def self.is_queue_locked?(queue)
  redis.exists("queue-lock:#{queue}")
end

.is_queue_serial?(queue) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/resque/plugins/serial_queues.rb', line 16

def self.is_queue_serial?(queue)
  config.serial_queues.include?(queue.to_s)
end

.lock_queue(queue) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/resque/plugins/serial_queues.rb', line 24

def self.lock_queue(queue)
  if redis.setnx("queue-lock:#{queue}", 1)
    redis.expire("queue-lock:#{queue}", config.lock_timeout)
    true
  else
    false
  end
end

.unlock_queue(queue) ⇒ Object



33
34
35
# File 'lib/resque/plugins/serial_queues.rb', line 33

def self.unlock_queue(queue)
  redis.del("queue-lock:#{queue}")
end

Instance Method Details

#configObject



4
5
6
# File 'lib/resque/plugins/serial_queues.rb', line 4

def config
  @config ||= Config.new
end

#configure {|config| ... } ⇒ Object

Yields:



8
9
10
# File 'lib/resque/plugins/serial_queues.rb', line 8

def configure
  yield(config) if block_given?
end

#redisObject



12
13
14
# File 'lib/resque/plugins/serial_queues.rb', line 12

def redis
  @redis ||= Redis::Namespace.new(:serial_queues, redis: Resque.redis)
end