Class: Qs::Queue
- Inherits:
-
Object
- Object
- Qs::Queue
- Defined in:
- lib/qs/queue.rb
Defined Under Namespace
Modules: RedisKey
Constant Summary collapse
- InvalidError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#enqueued_jobs ⇒ Object
readonly
Returns the value of attribute enqueued_jobs.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #enqueue(job_name, params = nil) ⇒ Object (also: #add)
-
#initialize(&block) ⇒ Queue
constructor
A new instance of Queue.
- #inspect ⇒ Object
- #job(name, handler_name) ⇒ Object
- #job_handler_ns(value = nil) ⇒ Object
- #name(value = nil) ⇒ Object
- #redis_key ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize(&block) ⇒ Queue
Returns a new instance of Queue.
10 11 12 13 14 15 |
# File 'lib/qs/queue.rb', line 10 def initialize(&block) @routes = [] @enqueued_jobs = [] self.instance_eval(&block) if !block.nil? raise InvalidError, "a queue must have a name" if self.name.nil? end |
Instance Attribute Details
#enqueued_jobs ⇒ Object (readonly)
Returns the value of attribute enqueued_jobs.
8 9 10 |
# File 'lib/qs/queue.rb', line 8 def enqueued_jobs @enqueued_jobs end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
7 8 9 |
# File 'lib/qs/queue.rb', line 7 def routes @routes end |
Instance Method Details
#enqueue(job_name, params = nil) ⇒ Object Also known as: add
39 40 41 |
# File 'lib/qs/queue.rb', line 39 def enqueue(job_name, params = nil) Qs.enqueue(self, job_name, params) end |
#inspect ⇒ Object
48 49 50 51 52 53 |
# File 'lib/qs/queue.rb', line 48 def inspect reference = '0x0%x' % (self.object_id << 1) "#<#{self.class}:#{reference} " \ "@name=#{self.name.inspect} " \ "@job_handler_ns=#{self.job_handler_ns.inspect}>" end |
#job(name, handler_name) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/qs/queue.rb', line 31 def job(name, handler_name) if self.job_handler_ns && !(handler_name =~ /^::/) handler_name = "#{self.job_handler_ns}::#{handler_name}" end @routes.push(Qs::Route.new(name, handler_name)) end |
#job_handler_ns(value = nil) ⇒ Object
26 27 28 29 |
# File 'lib/qs/queue.rb', line 26 def job_handler_ns(value = nil) @job_handler_ns = value if !value.nil? @job_handler_ns end |
#name(value = nil) ⇒ Object
17 18 19 20 |
# File 'lib/qs/queue.rb', line 17 def name(value = nil) @name = value if !value.nil? @name end |
#redis_key ⇒ Object
22 23 24 |
# File 'lib/qs/queue.rb', line 22 def redis_key @redis_key ||= RedisKey.new(self.name) end |
#reset! ⇒ Object
44 45 46 |
# File 'lib/qs/queue.rb', line 44 def reset! self.enqueued_jobs.clear end |