lib/good_job/capsule.rb in good_job-3.27.4 vs lib/good_job/capsule.rb in good_job-3.28.0
- old
+ new
@@ -10,11 +10,11 @@
# List of all instantiated Capsules in the current process.
# @return [Array<GoodJob::Capsule>, nil]
cattr_reader :instances, default: Concurrent::Array.new, instance_reader: false
# @param configuration [GoodJob::Configuration] Configuration to use for this capsule.
- def initialize(configuration: GoodJob.configuration)
+ def initialize(configuration: nil)
@configuration = configuration
@startable = true
@started_at = nil
@mutex = Mutex.new
@@ -28,17 +28,17 @@
@mutex.synchronize do
return unless startable?(force: force)
@shared_executor = GoodJob::SharedExecutor.new
- @notifier = GoodJob::Notifier.new(enable_listening: @configuration.enable_listen_notify, executor: @shared_executor.executor)
- @poller = GoodJob::Poller.new(poll_interval: @configuration.poll_interval)
- @multi_scheduler = GoodJob::MultiScheduler.from_configuration(@configuration, warm_cache_on_initialize: true)
+ @notifier = GoodJob::Notifier.new(enable_listening: configuration.enable_listen_notify, executor: @shared_executor.executor)
+ @poller = GoodJob::Poller.new(poll_interval: configuration.poll_interval)
+ @multi_scheduler = GoodJob::MultiScheduler.from_configuration(configuration, warm_cache_on_initialize: true)
@notifier.recipients.push([@multi_scheduler, :create_thread])
@poller.recipients.push(-> { @multi_scheduler.create_thread({ fanout: true }) })
- @cron_manager = GoodJob::CronManager.new(@configuration.cron_entries, start_on_initialize: true, executor: @shared_executor.executor) if @configuration.enable_cron?
+ @cron_manager = GoodJob::CronManager.new(configuration.cron_entries, start_on_initialize: true, executor: @shared_executor.executor) if configuration.enable_cron?
@startable = false
@started_at = Time.current
end
end
@@ -49,11 +49,11 @@
# * +0+ will interrupt active threads.
# * +N+ will wait at most N seconds and then interrupt active threads.
# * +nil+ will trigger a shutdown but not wait for it to complete.
# @return [void]
def shutdown(timeout: NONE)
- timeout = @configuration.shutdown_timeout if timeout == NONE
+ timeout = configuration.shutdown_timeout if timeout == NONE
GoodJob._shutdown_all([@shared_executor, @notifier, @poller, @multi_scheduler, @cron_manager].compact, timeout: timeout)
@startable = false
@started_at = nil
end
@@ -98,9 +98,13 @@
start if startable?
@multi_scheduler&.create_thread(job_state)
end
private
+
+ def configuration
+ @configuration || GoodJob.configuration
+ end
def startable?(force: false)
!@started_at && (@startable || force)
end
end