mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
FEATURE: Discoruse.handle_exception
to report exception via sidekiq helper, adds extra context
This commit is contained in:
parent
d95887c57d
commit
2ab76f60d1
4 changed files with 39 additions and 6 deletions
|
@ -35,7 +35,7 @@ if Sidekiq.server?
|
|||
manager.tick
|
||||
rescue => e
|
||||
# the show must go on
|
||||
Scheduler::Manager.handle_exception(e)
|
||||
Discourse.handle_exception(e)
|
||||
end
|
||||
sleep 1
|
||||
end
|
||||
|
|
|
@ -4,6 +4,21 @@ require_dependency 'auth/default_current_user_provider'
|
|||
|
||||
module Discourse
|
||||
|
||||
class SidekiqExceptionHandler
|
||||
extend Sidekiq::ExceptionHandler
|
||||
end
|
||||
|
||||
def self.handle_exception(ex, context=nil, parent_logger = nil)
|
||||
context ||= {}
|
||||
parent_logger ||= SidekiqExceptionHandler
|
||||
|
||||
cm = RailsMultisite::ConnectionManagement
|
||||
parent_logger.handle_exception(ex, {
|
||||
current_db: cm.current_db,
|
||||
current_hostname: cm.current_hostname
|
||||
}.merge(context))
|
||||
end
|
||||
|
||||
# Expected less matches than what we got in a find
|
||||
class TooManyMatches < Exception; end
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
module Scheduler
|
||||
class Manager
|
||||
extend Sidekiq::ExceptionHandler
|
||||
attr_accessor :random_ratio, :redis
|
||||
|
||||
|
||||
|
@ -41,13 +40,13 @@ module Scheduler
|
|||
def keep_alive
|
||||
@manager.keep_alive
|
||||
rescue => ex
|
||||
Scheduler::Manager.handle_exception(ex)
|
||||
Discourse.handle_exception(ex)
|
||||
end
|
||||
|
||||
def reschedule_orphans
|
||||
@manager.reschedule_orphans!
|
||||
rescue => ex
|
||||
Scheduler::Manager.handle_exception(ex)
|
||||
Discourse.handle_exception(ex)
|
||||
end
|
||||
|
||||
def process_queue
|
||||
|
@ -62,7 +61,7 @@ module Scheduler
|
|||
@mutex.synchronize { info.write! }
|
||||
klass.new.perform
|
||||
rescue => e
|
||||
Scheduler::Manager.handle_exception(e)
|
||||
Discourse.handle_exception(e)
|
||||
failed = true
|
||||
end
|
||||
duration = ((Time.now.to_f - start) * 1000).to_i
|
||||
|
@ -73,7 +72,7 @@ module Scheduler
|
|||
@mutex.synchronize { info.write! }
|
||||
end
|
||||
rescue => ex
|
||||
Scheduler::Manager.handle_exception(ex)
|
||||
Discourse.handle_exception(ex)
|
||||
ensure
|
||||
@running = false
|
||||
end
|
||||
|
|
|
@ -116,5 +116,24 @@ describe Discourse do
|
|||
|
||||
end
|
||||
|
||||
context "#handle_exception" do
|
||||
class TempLogger
|
||||
attr_accessor :exception, :context
|
||||
def handle_exception(exception, context)
|
||||
self.exception = exception
|
||||
self.context = context
|
||||
end
|
||||
end
|
||||
|
||||
it "should not fail when called" do
|
||||
logger = TempLogger.new
|
||||
exception = StandardError.new
|
||||
|
||||
Discourse.handle_exception(exception, nil, logger)
|
||||
logger.exception.should == exception
|
||||
logger.context.keys.should == [:current_db, :current_hostname]
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue