Class: Bizside::ResqueScheduler::FailureHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/bizside/resque.rb

Class Method Summary collapse

Class Method Details

.on_enqueue_failure(payload, exception) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/bizside/resque.rb', line 189

def self.on_enqueue_failure(payload, exception)
  ::Resque::Scheduler::FailureHandler.on_enqueue_failure(payload, exception)

  return if Bizside.rails_env&.test?

  ::Bizside.logger.error [
    "[FATAL] Resque::Scheduler",
    "#{payload}",
    "#{exception.class} #{exception.to_s}",
    "#{Array(exception.backtrace).join("\n")}"
  ].join("\n")

  @hostname ||= begin
    n = (Socket.gethostname rescue nil).to_s
    n = nil if n.empty?
    if n.nil?
      n = (`hostname`.to_s.strip rescue nil)
      n = nil if n && n.empty?
    end
    n || '(unknown)'
  end

  info = {
    time: Time.now.strftime('%Y-%m-%dT%H:%M:%S.%3N%z'),
    env: ENV['X-BIZSIDE-ENV'].presence || ENV['RAILS_ENV'],
    add_on_name: Bizside.config.add_on_name,
    server_address: @hostname,
    class: payload['class'],
    args: payload['args'].to_s,
    exception: exception.class,
    exception_message:  exception.to_s,
    exception_backtrace: Array(exception.backtrace)[0..10].join("\n") # Get only the top 10 because there are many traces.
  }
  ::Bizside::Audit::JobLogger.logger.record(info)
end