lib/good_job.rb in good_job-3.3.0 vs lib/good_job.rb in good_job-3.3.1
- old
+ new
@@ -1,22 +1,32 @@
# frozen_string_literal: true
require "active_job"
require "active_job/queue_adapters"
-require "zeitwerk"
-zeitwerk_options = Gem::Version.new(Zeitwerk::VERSION) >= Gem::Version.new("2.6.0") ? { warn_on_extra_files: false } : {}
-Zeitwerk::Loader.for_gem(**zeitwerk_options).tap do |loader|
- loader.inflector.inflect({
- "cli" => "CLI",
- })
- loader.push_dir("#{__dir__}/models")
- loader.ignore("#{__dir__}/generators")
- loader.setup
-end
-
+require "good_job/version"
require "good_job/engine"
+require "good_job/adapter"
+require "active_job/queue_adapters/good_job_adapter"
+require "good_job/active_job_extensions/concurrency"
+
+require "good_job/assignable_connection"
+require "good_job/cleanup_tracker"
+require "good_job/cli"
+require "good_job/configuration"
+require "good_job/cron_manager"
+require 'good_job/current_thread'
+require "good_job/daemon"
+require "good_job/dependencies"
+require "good_job/job_performer"
+require "good_job/log_subscriber"
+require "good_job/multi_scheduler"
+require "good_job/notifier"
+require "good_job/poller"
+require "good_job/probe_server"
+require "good_job/scheduler"
+
# GoodJob is a multithreaded, Postgres-based, ActiveJob backend for Ruby on Rails.
#
# +GoodJob+ is the top-level namespace and exposes configuration attributes.
module GoodJob
include GoodJob::Dependencies
@@ -67,10 +77,16 @@
# # config/initializers/good_job.rb
# GoodJob.on_thread_error = -> (exception) { Raven.capture_exception(exception) }
# @return [Proc, nil]
mattr_accessor :on_thread_error, default: nil
+ # @!attribute [rw] configuration
+ # @!scope class
+ # Global configuration object for GoodJob.
+ # @return [GoodJob::Configuration, nil]
+ mattr_accessor :configuration, default: GoodJob::Configuration.new({})
+
# Called with exception when a GoodJob thread raises an exception
# @param exception [Exception] Exception that was raised
# @return [void]
def self._on_thread_error(exception)
on_thread_error.call(exception) if on_thread_error.respond_to?(:call)
@@ -133,13 +149,12 @@
# If you are preserving job records this way, use this method regularly to
# destroy old records and preserve space in your database.
# @params older_than [nil,Numeric,ActiveSupport::Duration] Jobs older than this will be destroyed (default: +86400+).
# @return [Integer] Number of jobs that were destroyed.
def self.cleanup_preserved_jobs(older_than: nil)
- configuration = GoodJob::Configuration.new({})
- older_than ||= configuration.cleanup_preserved_jobs_before_seconds_ago
+ older_than ||= GoodJob.configuration.cleanup_preserved_jobs_before_seconds_ago
timestamp = Time.current - older_than
- include_discarded = configuration.cleanup_discarded_jobs?
+ include_discarded = GoodJob.configuration.cleanup_discarded_jobs?
ActiveSupport::Notifications.instrument("cleanup_preserved_jobs.good_job", { older_than: older_than, timestamp: timestamp }) do |payload|
old_jobs = GoodJob::Job.where('finished_at <= ?', timestamp)
old_jobs = old_jobs.not_discarded unless include_discarded
old_jobs_count = old_jobs.count