Class: RqQueue
- Inherits:
-
Object
- Object
- RqQueue
- Defined in:
- lib/rq_queue.rb
Class Attribute Summary collapse
-
.benchmark ⇒ Object
Returns the value of attribute benchmark.
Instance Attribute Summary collapse
-
#logger ⇒ Object
Returns the value of attribute logger.
Class Method Summary collapse
- .add_event(method_name, *args) ⇒ Object
-
.add_event_in(times, method_name, *args) ⇒ Object
For resque-scheduler.
- .enqueue(method_name, *args) ⇒ Object
-
.enqueue_in(times, method_name, *args) ⇒ Object
For resque-scheduler.
- .extract_queue_name ⇒ Object
- .inherited(subclass) ⇒ Object
- .instance ⇒ Object
- .logger ⇒ Object
- .logger_path ⇒ Object
- .logger_path=(_logger_path) ⇒ Object
- .method_missing(method, *args) ⇒ Object
- .notify_about_error(exception) ⇒ Object
- .perform(method_name, args) ⇒ Object
-
.proxy(method_name) ⇒ Object
proxing method for tests.
- .queue_name ⇒ Object
- .set_queue_name(queue_name) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ RqQueue
constructor
A new instance of RqQueue.
- #queue_name ⇒ Object
Constructor Details
#initialize ⇒ RqQueue
Returns a new instance of RqQueue.
103 104 105 |
# File 'lib/rq_queue.rb', line 103 def initialize self.logger = self.class.logger end |
Class Attribute Details
.benchmark ⇒ Object
Returns the value of attribute benchmark.
100 101 102 |
# File 'lib/rq_queue.rb', line 100 def benchmark @benchmark end |
Instance Attribute Details
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/rq_queue.rb', line 10 def logger @logger end |
Class Method Details
.add_event(method_name, *args) ⇒ Object
30 31 32 |
# File 'lib/rq_queue.rb', line 30 def self.add_event(method_name, *args) Resque.enqueue(self, method_name.to_s, args) end |
.add_event_in(times, method_name, *args) ⇒ Object
For resque-scheduler
45 46 47 |
# File 'lib/rq_queue.rb', line 45 def self.add_event_in(times, method_name, *args) Resque.enqueue_in(times, self, method_name.to_s, args) end |
.enqueue(method_name, *args) ⇒ Object
34 35 36 |
# File 'lib/rq_queue.rb', line 34 def self.enqueue(method_name, *args) add_event method_name, *args end |
.enqueue_in(times, method_name, *args) ⇒ Object
For resque-scheduler
50 51 52 |
# File 'lib/rq_queue.rb', line 50 def self.enqueue_in(times, method_name, *args) add_event_in(times, method_name, *args) end |
.extract_queue_name ⇒ Object
16 17 18 |
# File 'lib/rq_queue.rb', line 16 def self.extract_queue_name name.gsub(/^Rq/, '').underscore.gsub('/', '-').to_sym rescue :default end |
.inherited(subclass) ⇒ Object
12 13 14 |
# File 'lib/rq_queue.rb', line 12 def self.inherited(subclass) subclass.set_queue_name(subclass.extract_queue_name) end |
.instance ⇒ Object
64 65 66 |
# File 'lib/rq_queue.rb', line 64 def self.instance @instance ||= self.new end |
.logger ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rq_queue.rb', line 56 def self.logger @logger ||= Logger.new(logger_path).tap do |logger| logger.formatter = lambda { |s, d, p, m| "#{d.strftime("%d.%m.%Y %H:%M:%S")} #{m}\n" } # Rails.logger = logger if defined?(Rails) # ActiveRecord::Base.logger = logger if defined?(ActiveRecord) end end |
.logger_path ⇒ Object
94 95 96 97 98 |
# File 'lib/rq_queue.rb', line 94 def logger_path @logger_path ||= begin "#{Rails.root}/log/workers/#{extract_queue_name}.log" end end |
.logger_path=(_logger_path) ⇒ Object
90 91 92 |
# File 'lib/rq_queue.rb', line 90 def logger_path=(_logger_path) @logger_path = _logger_path end |
.method_missing(method, *args) ⇒ Object
38 39 40 |
# File 'lib/rq_queue.rb', line 38 def self.method_missing(method, *args) add_event(method, *args) end |
.notify_about_error(exception) ⇒ Object
111 112 113 |
# File 'lib/rq_queue.rb', line 111 def self.notify_about_error(exception) # stub end |
.perform(method_name, args) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/rq_queue.rb', line 68 def self.perform(method_name, args) start_time = benchmark ? Time.now : nil instance.send(method_name, *args) logger.info "done #{method_name}, #{"%.6f" % (Time.now - start_time)} s" if benchmark rescue => ex logger.error "!Failed event: #{method_name} => #{ex.}" notify_about_error(ex) raise ex end |
.proxy(method_name) ⇒ Object
proxing method for tests
82 83 84 85 86 87 |
# File 'lib/rq_queue.rb', line 82 def self.proxy(method_name) self.should_receive(method_name) do |*data| x = ::Resque.decode(::Resque.encode(data)) self.instance.send(method_name, *x) end.any_number_of_times end |
.queue_name ⇒ Object
24 25 26 |
# File 'lib/rq_queue.rb', line 24 def self.queue_name @queue end |
.set_queue_name(queue_name) ⇒ Object
20 21 22 |
# File 'lib/rq_queue.rb', line 20 def self.set_queue_name(queue_name) self.instance_variable_set('@queue', queue_name.to_sym) end |
Instance Method Details
#queue_name ⇒ Object
107 108 109 |
# File 'lib/rq_queue.rb', line 107 def queue_name self.class.queue_name end |