<commit_before>require 'delayed_job'
require 'rollbar/plugins/delayed_job/job_data'

module Rollbar
  module Delayed
    class << self
      attr_accessor :wrapped
    end

    class RollbarPlugin < ::Delayed::Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job, &Delayed::invoke_job_callback)
        lifecycle.after(:failure) do |_, job, _, _|
          data = Rollbar::Delayed.build_job_data(job)
          ::Rollbar.scope(:request => data).error(job.last_error, :use_exception_level_filters => true) if job.last_error
        end
      end
    end

    self.wrapped = false

    def self.wrap_worker
      return if wrapped

      ::Delayed::Worker.plugins << RollbarPlugin

      self.wrapped = true
    end

    def self.wrap_worker!
      self.wrapped = false

      wrap_worker
    end

    def self.invoke_job_callback
      proc do |job, *args, &block|
        begin
          block.call(job, *args)
        rescue => e
          report(e, job)

          raise e
        end
      end
    end

    def self.report(e, job)
      return if skip_report?(job)

      data = build_job_data(job)

      ::Rollbar.scope(:request => data).error(e, :use_exception_level_filters => true)
    end

    def self.skip_report?(job)
      job.attempts < ::Rollbar.configuration.dj_threshold
    end

    def self.build_job_data(job)
      return nil unless ::Rollbar.configuration.report_dj_data

      JobData.new(job).to_hash
    end
  end
end
<commit_msg>Make the on job failure message more clear<commit_after>require 'delayed_job'
require 'rollbar/plugins/delayed_job/job_data'

module Rollbar
  module Delayed
    class << self
      attr_accessor :wrapped
    end

    class RollbarPlugin < ::Delayed::Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job, &Delayed::invoke_job_callback)
        lifecycle.after(:failure) do |_, job, _, _|
          data = Rollbar::Delayed.build_job_data(job)
          ::Rollbar.scope(:request => data).error("Job has failed and won't be retried anymore: " + job.last_error, :use_exception_level_filters => true) if job.last_error
        end
      end
    end

    self.wrapped = false

    def self.wrap_worker
      return if wrapped

      ::Delayed::Worker.plugins << RollbarPlugin

      self.wrapped = true
    end

    def self.wrap_worker!
      self.wrapped = false

      wrap_worker
    end

    def self.invoke_job_callback
      proc do |job, *args, &block|
        begin
          block.call(job, *args)
        rescue => e
          report(e, job)

          raise e
        end
      end
    end

    def self.report(e, job)
      return if skip_report?(job)

      data = build_job_data(job)

      ::Rollbar.scope(:request => data).error(e, :use_exception_level_filters => true)
    end

    def self.skip_report?(job)
      job.attempts < ::Rollbar.configuration.dj_threshold
    end

    def self.build_job_data(job)
      return nil unless ::Rollbar.configuration.report_dj_data

      JobData.new(job).to_hash
    end
  end
end

{'fraction_non_alphanumeric': 0.09330695680844049, 'fraction_numerical': 0.0, 'mean_word_length': 2.463470319634703, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, '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': '6601273', 'n_tokens_mistral': 976, 'n_tokens_neox': 942, 'n_words': 215}