<commit_before>require "stringio"
require "pp"
require "sidekiq"
require "sidekiq_json_encoding_patch"

class FailedJobWorker
  include Sidekiq::Worker
  sidekiq_options :retry => false

  def logger
    Logging.logger[self]
  end

  sidekiq_options :queue => :failed

  def perform(job_info)
    # `job_info` is the same format at Sidekiq's job format, as serialised to
    # JSON and passed into Redis
    begin
      mailer = settings.mailer
    rescue NoMethodError  # If the initialiser isn't in place
      mailer = nil
    end

    unless mailer
      logger.warn "No mailer configured for failed job: discarding"
      logger.debug job_info
      return
    end

    message_body = StringIO.new
    message_body << introduction
    message_body << "\n\n"
    PP.pp(job_info, message_body)
    mailer.send_email("Job failure", message_body.string)
  end

private
  def introduction
    "The following job failed submission to elasticsearch:"
  end
end
<commit_msg>Consolidate Sidekiq options for failed job worker.<commit_after>require "stringio"
require "pp"
require "sidekiq"
require "sidekiq_json_encoding_patch"

class FailedJobWorker
  include Sidekiq::Worker
  sidekiq_options :retry => false, :queue => :failed

  def logger
    Logging.logger[self]
  end

  def perform(job_info)
    # `job_info` is the same format at Sidekiq's job format, as serialised to
    # JSON and passed into Redis
    begin
      mailer = settings.mailer
    rescue NoMethodError  # If the initialiser isn't in place
      mailer = nil
    end

    unless mailer
      logger.warn "No mailer configured for failed job: discarding"
      logger.debug job_info
      return
    end

    message_body = StringIO.new
    message_body << introduction
    message_body << "\n\n"
    PP.pp(job_info, message_body)
    mailer.send_email("Job failure", message_body.string)
  end

private
  def introduction
    "The following job failed submission to elasticsearch:"
  end
end

{'fraction_non_alphanumeric': 0.06731259561448241, 'fraction_numerical': 0.0, 'mean_word_length': 3.3215859030837005, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5182975', 'n_tokens_mistral': 608, 'n_tokens_neox': 596, 'n_words': 191}