<commit_before>module Resque
  module Pertry
    module Retry
      extend ActiveSupport::Concern

      included do
        class_attribute :_retry_delays
        class_attribute :_retry_delay
        class_attribute :_retry_attempts
        class_attribute :_retry_ttl
        class_attribute :_retry_exceptions

        # set a default max number of retry attempts
        set_retry_attempts 1

        # set job to expire in 1 week (we need a default so we can purge the database)
        set_retry_ttl 1.week
      end

      module ClassMethods
        
        # Sets a number of seconds to wait before retrying
        def set_retry_delay(delay)
          self._retry_delays = nil
          self._retry_delay = delay == :clear ? nil : Integer(delay)
        end
        
        def retry_delay
          self._retry_delay
        end

        # Sets a list of delays (list length will be the # of attempts)
        def set_retry_delays(*delays)
          set_retry_attempts :clear
          set_retry_delay :clear
          self._retry_delays = Array(delays).map { |delay| Integer(delay) }
        end

        def retry_delays
          self._retry_delays
        end

        # Sets the maximum number of times we will retry
        def set_retry_attempts(count)
          self._retry_delays = nil
          self._retry_attempts = count == :clear ? nil : Integer(count)
        end

        def retry_attempts
          self._retry_attempts
        end

        # Sets the maximum time-to-live of the job, after which no attempts will ever be made
        def set_retry_ttl(ttl)
          self._retry_ttl = ttl == :clear ? nil : Integer(ttl)
        end

        def retry_ttl
          self._retry_ttl
        end

        # Sets a list of exceptions that we want to retry
        # If none are set, we will retry every exceptions
        def set_retry_exceptions(*exceptions)
          self._retry_exceptions = Array(exceptions)
        end

        def retry_exceptions
          self._retry_exceptions
        end

        # Check if we will retry this job on failure
        # There has to be a constraint on the number of times we will retry a failing job
        # or have a ttl, otherwise we could be retrying job endlessly
        def retryable?
          retry_attempts || retry_delays || retry_ttl
        end

        # Resque around_perform hook
        def around_perform_pertry_00_retry(args = {})
          ResquePertryPersistence.trying_job(self, args)

          yield
        end

        # Resque on_failure hook (job failed)
        def on_failure_pertry_00_retry(exception, args = {})<commit_msg>add an easy way to reset all retry properties<commit_after>module Resque
  module Pertry
    module Retry
      extend ActiveSupport::Concern

      included do
        class_attribute :_retry_delays
        class_attribute :_retry_delay
        class_attribute :_retry_attempts
        class_attribute :_retry_ttl
        class_attribute :_retry_exceptions

        # set a default max number of retry attempts
        set_retry_attempts 1

        # set job to expire in 1 week (we need a default so we can purge the database)
        set_retry_ttl 1.week
      end

      module ClassMethods
        
        # Sets a number of seconds to wait before retrying
        def set_retry_delay(delay)
          self._retry_delays = nil
          self._retry_delay = delay == :clear ? nil : Integer(delay)
        end
        
        def retry_delay
          self._retry_delay
        end

        # Sets a list of delays (list length will be the # of attempts)
        def set_retry_delays(*delays)
          set_retry_attempts :clear
          set_retry_delay :clear
          self._retry_delays = Array(delays).map { |delay| Integer(delay) }
        end

        def retry_delays
          self._retry_delays
        end

        # Sets the maximum number of times we will retry
        def set_retry_attempts(count)
          self._retry_delays = nil
          self._retry_attempts = count == :clear ? nil : Integer(count)
        end

        def retry_attempts
          self._retry_attempts
        end

        # Sets the maximum time-to-live of the job, after which no attempts will ever be made
        def set_retry_ttl(ttl)
          self._retry_ttl = ttl == :clear ? nil : Integer(ttl)
        end

        def retry_ttl
          self._retry_ttl
        end

        # Sets a list of exceptions that we want to retry
        # If none are set, we will retry every exceptions
        def set_retry_exceptions(*exceptions)
          self._retry_exceptions = Array(exceptions)
        end

        def retry_exceptions
          self._retry_exceptions
        end

        # Quickly reset all retry properties
        # Useful if you have a base job class
        def reset_retry_properties
          self._retry_delays = nil
          self._retry_attempts = nil
          self._retry_delays = nil
          self._retry_ttl = nil
          self._retry_exceptions = nil
        end

        # Check if we will retry this job on failure
        # There has to be a constraint on the number of times we will retry a failing job
        # or have a ttl, otherwise we could be retrying job endlessly
        def retryable?
          retry_attempts || retry_delays || retry_ttl
        end

        # Resque around_perform hook
        def around_perform_pertry_00_retry(args = {})
          ResquePertryPersistence.trying_job(self, args)

          yield
        end

        # Resque on_failure hook (job failed)
        def on_failure_pertry_00_retry(exception, args = {})
{'fraction_non_alphanumeric': 0.04530051721062957, 'fraction_numerical': 0.0024968789013732834, 'mean_word_length': 1.9422875131164743, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1849052', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1570, 'n_words': 514}