Class: JobQueue
- Inherits:
-
Object
- Object
- JobQueue
- Defined in:
- lib/job_queue/job_queue.rb
Overview
JobQueue abstracts the task of adding work to a queue.
Beanstalk is fantastic, but maybe not “enterprise grade”.
AMQP is fantastic, but it’s bloody complex and has to run inside an eventmachine loop.
Take your pick!
Before use, an adapter must be chosen:
JobQueue.adapter = JobQueue::BeanstalkAdapter.new
Jobs can then be simply added to the queue with
JobQueue.put("flubble bubble")
Defined Under Namespace
Classes: AMQPAdapter, ArgumentError, BeanstalkAdapter, NoConnectionAvailable, TestAdapter, VerboseAdapter
Class Attribute Summary collapse
-
.adapter ⇒ Object
Returns the value of attribute adapter.
-
.logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
-
.job_stats(job_id) ⇒ Object
Returns a hash of info (exact details dependent on adapter).
- .put(string, options = {}) ⇒ Object
- .queue_length(queue = nil) ⇒ Object
- .subscribe(options = {}, &block) ⇒ Object
Class Attribute Details
.adapter ⇒ Object
Returns the value of attribute adapter.
20 21 22 |
# File 'lib/job_queue/job_queue.rb', line 20 def adapter @adapter end |
.logger ⇒ Object
Returns the value of attribute logger.
21 22 23 |
# File 'lib/job_queue/job_queue.rb', line 21 def logger @logger end |
Class Method Details
.job_stats(job_id) ⇒ Object
Returns a hash of info (exact details dependent on adapter)
58 59 60 |
# File 'lib/job_queue/job_queue.rb', line 58 def self.job_stats(job_id) adapter.job_stats(job_id) end |
.put(string, options = {}) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/job_queue/job_queue.rb', line 33 def self.put(string, = {}) queue = [:queue] || 'default' priority = [:priority] || 50 ttr = [:ttr] || 60 adapter.put(string, queue, priority, ttr) end |
.queue_length(queue = nil) ⇒ Object
62 63 64 |
# File 'lib/job_queue/job_queue.rb', line 62 def self.queue_length(queue = nil) adapter.queue_length(queue) end |
.subscribe(options = {}, &block) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/job_queue/job_queue.rb', line 40 def self.subscribe( = {}, &block) queue = [:queue] || 'default' error_report = [:error_report] || Proc.new do |job_body, e| JobQueue.logger.error \ "Job failed\n" \ "==========\n" \ "Job content: #{job_body.inspect}\n" \ "Exception: #{e.}\n" \ "#{e.backtrace.join("\n")}\n" \ "\n" end cleanup_task = [:cleanup] || lambda {} catch :stop do adapter.subscribe(error_report, cleanup_task, queue, &block) end end |