Sha256: b4d5412bf324345d36ebd6403e72337bdfe2c50f622cf4860aae2a669184e4b1

Contents?: true

Size: 996 Bytes

Versions: 59

Compression:

Stored size: 996 Bytes

Contents

# frozen_string_literal: true
module GoodJob # :nodoc:
  # Tracks thresholds for cleaning up old jobs.
  class CleanupTracker
    attr_accessor :cleanup_interval_seconds,
                  :cleanup_interval_jobs,
                  :job_count,
                  :last_at

    def initialize(cleanup_interval_seconds: nil, cleanup_interval_jobs: nil)
      self.cleanup_interval_seconds = cleanup_interval_seconds
      self.cleanup_interval_jobs = cleanup_interval_jobs

      reset
    end

    # Increments job count.
    # @return [void]
    def increment
      self.job_count += 1
    end

    # Whether a cleanup should be run.
    # @return [Boolean]
    def cleanup?
      (cleanup_interval_jobs && job_count > cleanup_interval_jobs) ||
        (cleanup_interval_seconds && last_at < Time.current - cleanup_interval_seconds) ||
        false
    end

    # Resets the counters.
    # @return [void]
    def reset
      self.job_count = 0
      self.last_at = Time.current
    end
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
good_job-3.7.2 lib/good_job/cleanup_tracker.rb
good_job-3.7.1 lib/good_job/cleanup_tracker.rb
good_job-3.7.0 lib/good_job/cleanup_tracker.rb
good_job-3.6.2 lib/good_job/cleanup_tracker.rb
good_job-3.6.1 lib/good_job/cleanup_tracker.rb
good_job-3.6.0 lib/good_job/cleanup_tracker.rb
good_job-3.5.1 lib/good_job/cleanup_tracker.rb
good_job-3.5.0 lib/good_job/cleanup_tracker.rb
good_job-3.4.8 lib/good_job/cleanup_tracker.rb
good_job-3.4.7 lib/good_job/cleanup_tracker.rb
good_job-3.4.6 lib/good_job/cleanup_tracker.rb
good_job-3.4.5 lib/good_job/cleanup_tracker.rb
good_job-3.4.4 lib/good_job/cleanup_tracker.rb
good_job-3.4.3 lib/good_job/cleanup_tracker.rb
good_job-3.4.2 lib/good_job/cleanup_tracker.rb
good_job-3.4.1 lib/good_job/cleanup_tracker.rb
good_job-3.4.0 lib/good_job/cleanup_tracker.rb
good_job-3.3.3 lib/good_job/cleanup_tracker.rb
good_job-3.3.2 lib/good_job/cleanup_tracker.rb
good_job-3.3.1 lib/good_job/cleanup_tracker.rb