lib/good_job/adapter.rb in good_job-1.1.3 vs lib/good_job/adapter.rb in good_job-1.1.4

- old
+ new

@@ -1,28 +1,30 @@ module GoodJob class Adapter EXECUTION_MODES = [:async, :external, :inline].freeze - def initialize(execution_mode: nil, max_threads: nil, poll_interval: nil, scheduler: nil, inline: false) + def initialize(execution_mode: nil, queues: nil, max_threads: nil, poll_interval: nil, scheduler: nil, notifier: nil, inline: false) if inline && execution_mode.nil? ActiveSupport::Deprecation.warn('GoodJob::Adapter#new(inline: true) is deprecated; use GoodJob::Adapter.new(execution_mode: :inline) instead') execution_mode = :inline end - configuration = GoodJob::Configuration.new({ - execution_mode: execution_mode, - max_threads: max_threads, - poll_interval: poll_interval, - }, - env: ENV) + configuration = GoodJob::Configuration.new( + execution_mode: execution_mode, + queues: queues, + max_threads: max_threads, + poll_interval: poll_interval + ) - raise ArgumentError, "execution_mode: must be one of #{EXECUTION_MODES.join(', ')}." unless EXECUTION_MODES.include?(configuration.execution_mode) - @execution_mode = configuration.execution_mode + raise ArgumentError, "execution_mode: must be one of #{EXECUTION_MODES.join(', ')}." unless EXECUTION_MODES.include?(@execution_mode) - @scheduler = scheduler - @scheduler = GoodJob::Scheduler.from_configuration(configuration) if @execution_mode == :async && @scheduler.blank? + if @execution_mode == :async # rubocop:disable Style/GuardClause + @notifier = notifier || GoodJob::Notifier.new + @scheduler = scheduler || GoodJob::Scheduler.from_configuration(configuration) + @notifier.recipients << [@scheduler, :create_thread] + end end def enqueue(active_job) enqueue_at(active_job, nil) end @@ -40,15 +42,17 @@ ensure good_job.advisory_unlock end end - @scheduler.create_thread if execute_async? + executed_locally = execute_async? && @scheduler.create_thread(queue_name: good_job.queue_name) + Notifier.notify(queue_name: good_job.queue_name) unless executed_locally good_job end def shutdown(wait: true) + @notifier&.shutdown(wait: wait) @scheduler&.shutdown(wait: wait) end def execute_async? @execution_mode == :async