Permalink
Browse files

Add exception logging and reporting to queue worker

  • Loading branch information...
1 parent 63bd8e8 commit af6cb127f056cf021df3da0ac002b861f8f50196 @rwdaigle committed Oct 8, 2012
Showing with 28 additions and 5 deletions.
  1. +1 −0 Gemfile
  2. +1 −0 Gemfile.lock
  3. +1 −1 Procfile
  4. +17 −4 app/models/gisted_worker.rb
  5. +8 −0 config/initializers/logging.rb
View
@@ -1,6 +1,7 @@
source 'https://rubygems.org'
gem 'rails', '3.2.8'
+gem 'rake'
gem 'thin'
gem 'pg'
View
@@ -193,6 +193,7 @@ DEPENDENCIES
queue_classic
rack-worker
rails (= 3.2.8)
+ rake
sass-rails (~> 3.2.3)
scrolls
thin
View
@@ -1,3 +1,3 @@
web: bundle exec thin start -p $PORT
-worker: bundle exec rake gisted:work
+worker: bundle exec rake gisted:work --trace
kanshi: bundle exec kanshi
@@ -5,10 +5,23 @@ class GistedWorker < QC::Worker
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
add_transaction_tracer :call, :category => :task, :params => '{ :job => args[0][:method], :args => args[0][:args] }'
- # # retry the job
- # def handle_failure(job, exception)
- # @queue.enqueue(job[:method], *job[:args])
- # end
+ FQ = QC::Queue.new 'failed'
+
+ def handle_failure(job, exception)
+
+ # From QC::Worker
+ klass = eval(job[:method].split(".").first)
+ message = job[:method].split(".").last
+
+ # Log exception & store failed job
+ FQ.enqueue(job[:method], *job[:args])
+ log_exception({ns: klass, fn: message, job_args: job[:args]}, exception)
+ Airbrake.notify(exception, parameters: job)
+
+ # # Retry
+ # log(ns: self, fn: __method__, at: 'retry-job', job: job[:method], job_args: job[:args])
+ # @queue.enqueue(job[:method], *job[:args])
+ end
# # the forked proc needs a new db connection
# def setup_child
@@ -25,6 +25,10 @@ def log(*segments, &block)
Scrolls.log(log_data_from(*segments), &block)
end
+ def log_exception(*segments, exception)
+ Scrolls.log_exception(log_data_from(*segments), exception)
+ end
+
private
def log_data_from(*segments)
@@ -38,6 +42,10 @@ def log_data_from(*segments)
def log(*segments, &block)
self.class.log(*segments, &block)
end
+
+ def log_exception(*segments, exception)
+ self.class.log_exception(*segments, exception)
+ end
end
class Hash

0 comments on commit af6cb12

Please sign in to comment.