lib/good_job/configuration.rb in good_job-3.7.2 vs lib/good_job/configuration.rb in good_job-3.7.3

- old
+ new

@@ -240,32 +240,75 @@ DEFAULT_CLEANUP_PRESERVED_JOBS_BEFORE_SECONDS_AGO ).to_i end # Number of jobs a {Scheduler} will execute before automatically cleaning up preserved jobs. + # Positive values will clean up after that many jobs have run, false or 0 will disable, and -1 will clean up after every job. # @return [Integer, nil] def cleanup_interval_jobs - value = if rails_config.key?(:cleanup_interval_jobs) - rails_config[:cleanup_interval_jobs] - elsif env.key?('GOOD_JOB_CLEANUP_INTERVAL_JOBS') - env['GOOD_JOB_CLEANUP_INTERVAL_JOBS'] - else - DEFAULT_CLEANUP_INTERVAL_JOBS - end - value.present? ? value.to_i : nil + if rails_config.key?(:cleanup_interval_jobs) + value = rails_config[:cleanup_interval_jobs] + if value.nil? + ActiveSupport::Deprecation.warn( + %(Setting `config.good_job.cleanup_interval_jobs` to `nil` will no longer disable count-based cleanups in GoodJob v4. Set to `false` to disable, or `-1` to run every time.) + ) + value = false + elsif value == 0 # rubocop:disable Style/NumericPredicate + ActiveSupport::Deprecation.warn( + %(Setting `config.good_job.cleanup_interval_jobs` to `0` will disable count-based cleanups in GoodJob v4. Set to `false` to disable, or `-1` to run every time.) + ) + value = -1 + end + elsif env.key?('GOOD_JOB_CLEANUP_INTERVAL_JOBS') + value = env['GOOD_JOB_CLEANUP_INTERVAL_JOBS'] + if value.blank? + ActiveSupport::Deprecation.warn( + %(Setting `GOOD_JOB_CLEANUP_INTERVAL_JOBS` to `""` will no longer disable count-based cleanups in GoodJob v4. Set to `0` to disable, or `-1` to run every time.) + ) + value = false + elsif value == '0' + value = false + end + else + value = DEFAULT_CLEANUP_INTERVAL_JOBS + end + + value ? value.to_i : false end # Number of seconds a {Scheduler} will wait before automatically cleaning up preserved jobs. + # Positive values will clean up after that many jobs have run, false or 0 will disable, and -1 will clean up after every job. # @return [Integer, nil] def cleanup_interval_seconds - value = if rails_config.key?(:cleanup_interval_seconds) - rails_config[:cleanup_interval_seconds] - elsif env.key?('GOOD_JOB_CLEANUP_INTERVAL_SECONDS') - env['GOOD_JOB_CLEANUP_INTERVAL_SECONDS'] - else - DEFAULT_CLEANUP_INTERVAL_SECONDS - end - value.present? ? value.to_i : nil + if rails_config.key?(:cleanup_interval_seconds) + value = rails_config[:cleanup_interval_seconds] + + if value.nil? + ActiveSupport::Deprecation.warn( + %(Setting `config.good_job.cleanup_interval_seconds` to `nil` will no longer disable time-based cleanups in GoodJob v4. Set to `false` to disable, or `-1` to run every time.) + ) + value = false + elsif value == 0 # rubocop:disable Style/NumericPredicate + ActiveSupport::Deprecation.warn( + %(Setting `config.good_job.cleanup_interval_seconds` to `0` will disable time-based cleanups in GoodJob v4. Set to `false` to disable, or `-1` to run every time.) + ) + value = -1 + end + elsif env.key?('GOOD_JOB_CLEANUP_INTERVAL_SECONDS') + value = env['GOOD_JOB_CLEANUP_INTERVAL_SECONDS'] + if value.blank? + ActiveSupport::Deprecation.warn( + %(Setting `GOOD_JOB_CLEANUP_INTERVAL_SECONDS` to `""` will no longer disable time-based cleanups in GoodJob v4. Set to `0` to disable, or `-1` to run every time.) + ) + value = false + elsif value == '0' + value = false + end + else + value = DEFAULT_CLEANUP_INTERVAL_SECONDS + end + + value ? value.to_i : false end # Tests whether to daemonize the process. # @return [Boolean] def daemonize?