lib/good_job.rb in good_job-3.99.1 vs lib/good_job.rb in good_job-4.0.0

- old
+ new

@@ -56,11 +56,11 @@ # Default logger for GoodJob; overridden by Rails.logger in Railtie. DEFAULT_LOGGER = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout)) # @!attribute [rw] active_record_parent_class # @!scope class - # The ActiveRecord parent class inherited by +GoodJob::Execution+ (default: +ActiveRecord::Base+). + # The ActiveRecord parent class inherited by +GoodJob::Job+ (default: +ActiveRecord::Base+). # Use this when using multiple databases or other custom ActiveRecord configuration. # @return [ActiveRecord::Base] # @example Change the base class: # GoodJob.active_record_parent_class = "CustomApplicationRecord" mattr_accessor :active_record_parent_class, default: nil @@ -131,10 +131,11 @@ # connects_to database: :special_database # end def self.configure_active_record(&block) self._active_record_configuration = block end + mattr_accessor :_active_record_configuration, default: nil # Stop executing jobs. # GoodJob does its work in pools of background threads. # When forking processes you should shut down these background threads before forking, and restart them after forking. @@ -206,45 +207,41 @@ older_than ||= GoodJob.configuration.cleanup_preserved_jobs_before_seconds_ago timestamp = Time.current - older_than include_discarded = GoodJob.configuration.cleanup_discarded_jobs? ActiveSupport::Notifications.instrument("cleanup_preserved_jobs.good_job", { older_than: older_than, timestamp: timestamp }) do |payload| - deleted_executions_count = 0 + deleted_jobs_count = 0 deleted_batches_count = 0 deleted_discrete_executions_count = 0 jobs_query = GoodJob::Job.finished_before(timestamp).order(finished_at: :asc).limit(in_batches_of) jobs_query = jobs_query.succeeded unless include_discarded loop do active_job_ids = jobs_query.pluck(:active_job_id) break if active_job_ids.empty? - if GoodJob::Execution.discrete_support? - deleted_discrete_executions = GoodJob::DiscreteExecution.where(active_job_id: active_job_ids).delete_all - deleted_discrete_executions_count += deleted_discrete_executions - end + deleted_discrete_executions = GoodJob::DiscreteExecution.where(active_job_id: active_job_ids).delete_all + deleted_discrete_executions_count += deleted_discrete_executions - deleted_executions = GoodJob::Execution.where(active_job_id: active_job_ids).delete_all - deleted_executions_count += deleted_executions + deleted_jobs = GoodJob::Job.where(active_job_id: active_job_ids).delete_all + deleted_jobs_count += deleted_jobs end - if GoodJob::BatchRecord.migrated? - batches_query = GoodJob::BatchRecord.finished_before(timestamp).limit(in_batches_of) - batches_query = batches_query.succeeded unless include_discarded - loop do - deleted = batches_query.delete_all - break if deleted.zero? + batches_query = GoodJob::BatchRecord.finished_before(timestamp).limit(in_batches_of) + batches_query = batches_query.succeeded unless include_discarded + loop do + deleted = batches_query.delete_all + break if deleted.zero? - deleted_batches_count += deleted - end + deleted_batches_count += deleted end payload[:destroyed_batches_count] = deleted_batches_count payload[:destroyed_discrete_executions_count] = deleted_discrete_executions_count - payload[:destroyed_executions_count] = deleted_executions_count + payload[:destroyed_jobs_count] = deleted_jobs_count - destroyed_records_count = deleted_batches_count + deleted_discrete_executions_count + deleted_executions_count + destroyed_records_count = deleted_batches_count + deleted_discrete_executions_count + deleted_jobs_count payload[:destroyed_records_count] = destroyed_records_count destroyed_records_count end end @@ -270,11 +267,11 @@ end # Tests whether GoodJob can be safely upgraded to v4 # @return [Boolean] def self.v4_ready? - GoodJob.migrated? && GoodJob::Job.discrete_support? && GoodJob::Job.where(finished_at: nil).where(is_discrete: [nil, false]).none? + GoodJob::Job.discrete_support? && GoodJob::Job.where(finished_at: nil).where(is_discrete: [nil, false]).none? end # Deprecator for providing deprecation warnings. # @return [ActiveSupport::Deprecation] def self.deprecator @@ -289,12 +286,10 @@ # Whether all GoodJob migrations have been applied. # For use in tests/CI to validate GoodJob is up-to-date. # @return [Boolean] def self.migrated? - # Always update with the most recent migration check - GoodJob::DiscreteExecution.reset_column_information - GoodJob::DiscreteExecution.duration_interval_migrated? + true end ActiveSupport.run_load_hooks(:good_job, self) end