Class: GoodJob::CleanupTracker
- Inherits:
-
Object
- Object
- GoodJob::CleanupTracker
- Defined in:
- lib/good_job/cleanup_tracker.rb
Overview
Tracks thresholds for cleaning up old jobs.
Instance Attribute Summary collapse
-
#cleanup_interval_jobs ⇒ Object
Returns the value of attribute cleanup_interval_jobs.
-
#cleanup_interval_seconds ⇒ Object
Returns the value of attribute cleanup_interval_seconds.
-
#job_count ⇒ Object
Returns the value of attribute job_count.
-
#last_at ⇒ Object
Returns the value of attribute last_at.
Instance Method Summary collapse
-
#cleanup? ⇒ Boolean
Whether a cleanup should be run.
-
#increment ⇒ Integer
Increments job count.
-
#initialize(cleanup_interval_seconds: false, cleanup_interval_jobs: false) ⇒ CleanupTracker
constructor
A new instance of CleanupTracker.
-
#reset ⇒ void
Resets the counters.
Constructor Details
#initialize(cleanup_interval_seconds: false, cleanup_interval_jobs: false) ⇒ CleanupTracker
Returns a new instance of CleanupTracker.
11 12 13 14 15 16 17 18 |
# File 'lib/good_job/cleanup_tracker.rb', line 11 def initialize(cleanup_interval_seconds: false, cleanup_interval_jobs: false) raise ArgumentError, "Do not use `0` for cleanup intervals. Use `false` to disable, or -1 to always run" if cleanup_interval_seconds == 0 || cleanup_interval_jobs == 0 # rubocop:disable Style/NumericPredicate self.cleanup_interval_seconds = cleanup_interval_seconds self.cleanup_interval_jobs = cleanup_interval_jobs reset end |
Instance Attribute Details
#cleanup_interval_jobs ⇒ Object
Returns the value of attribute cleanup_interval_jobs.
6 7 8 |
# File 'lib/good_job/cleanup_tracker.rb', line 6 def cleanup_interval_jobs @cleanup_interval_jobs end |
#cleanup_interval_seconds ⇒ Object
Returns the value of attribute cleanup_interval_seconds.
6 7 8 |
# File 'lib/good_job/cleanup_tracker.rb', line 6 def cleanup_interval_seconds @cleanup_interval_seconds end |
#job_count ⇒ Object
Returns the value of attribute job_count.
6 7 8 |
# File 'lib/good_job/cleanup_tracker.rb', line 6 def job_count @job_count end |
#last_at ⇒ Object
Returns the value of attribute last_at.
6 7 8 |
# File 'lib/good_job/cleanup_tracker.rb', line 6 def last_at @last_at end |
Instance Method Details
#cleanup? ⇒ Boolean
Whether a cleanup should be run.
28 29 30 31 32 |
# File 'lib/good_job/cleanup_tracker.rb', line 28 def cleanup? (cleanup_interval_jobs && job_count > cleanup_interval_jobs) || (cleanup_interval_seconds && last_at < Time.current - cleanup_interval_seconds) || false end |
#increment ⇒ Integer
Increments job count.
22 23 24 |
# File 'lib/good_job/cleanup_tracker.rb', line 22 def increment self.job_count += 1 end |
#reset ⇒ void
This method returns an undefined value.
Resets the counters.
36 37 38 39 |
# File 'lib/good_job/cleanup_tracker.rb', line 36 def reset self.job_count = 0 self.last_at = Time.current end |