lib/good_job/adapter.rb in good_job-3.3.0 vs lib/good_job/adapter.rb in good_job-3.3.1

- old
+ new

@@ -8,10 +8,12 @@ # @!scope class # List of all instantiated Adapters in the current process. # @return [Array<GoodJob::Adapter>, nil] cattr_reader :instances, default: [], instance_reader: false + attr_reader :execution_mode + # @param execution_mode [Symbol, nil] specifies how and where jobs should be executed. You can also set this with the environment variable +GOOD_JOB_EXECUTION_MODE+. # # - +:inline+ executes jobs immediately in whatever process queued them (usually the web server process). This should only be used in test and development environments. # - +:external+ causes the adapter to enqueue jobs, but not execute them. When using this option (the default for production environments), you'll need to use the command-line tool to actually execute your jobs. # - +:async+ (or +:async_server+) executes jobs in separate threads within the Rails web server process (`bundle exec rails server`). It can be more economical for small workloads because you don't need a separate machine or environment for running your jobs, but if your web server is under heavy load or your jobs require a lot of resources, you should choose +:external+ instead. @@ -23,12 +25,12 @@ # - +development+: +:async:+ # -+test+: +:inline+ # - +production+ and all other environments: +:external+ # def initialize(execution_mode: nil) - @configuration = GoodJob::Configuration.new({ execution_mode: execution_mode }) - @configuration.validate! + @execution_mode = (execution_mode || GoodJob.configuration.execution_mode).to_sym + GoodJob::Configuration.validate_execution_mode(@execution_mode) self.class.instances << self start_async if GoodJob.async_ready? end @@ -80,11 +82,11 @@ # * +0+, the scheduler will immediately shutdown and stop any threads. # * A positive number will wait that many seconds before stopping any remaining active threads. # @return [void] def shutdown(timeout: :default) timeout = if timeout == :default - @configuration.shutdown_timeout + GoodJob.configuration.shutdown_timeout else timeout end executables = [@notifier, @poller, @scheduler].compact @@ -93,38 +95,38 @@ end # Whether in +:async+ execution mode. # @return [Boolean] def execute_async? - @configuration.execution_mode == :async_all || - (@configuration.execution_mode.in?([:async, :async_server]) && in_server_process?) + execution_mode == :async_all || + (execution_mode.in?([:async, :async_server]) && in_server_process?) end # Whether in +:external+ execution mode. # @return [Boolean] def execute_externally? - @configuration.execution_mode == :external || - (@configuration.execution_mode.in?([:async, :async_server]) && !in_server_process?) + execution_mode == :external || + (execution_mode.in?([:async, :async_server]) && !in_server_process?) end # Whether in +:inline+ execution mode. # @return [Boolean] def execute_inline? - @configuration.execution_mode == :inline + execution_mode == :inline end # Start async executors # @return [void] def start_async return unless execute_async? @notifier = GoodJob::Notifier.new - @poller = GoodJob::Poller.new(poll_interval: @configuration.poll_interval) - @scheduler = GoodJob::Scheduler.from_configuration(@configuration, warm_cache_on_initialize: true) + @poller = GoodJob::Poller.new(poll_interval: GoodJob.configuration.poll_interval) + @scheduler = GoodJob::Scheduler.from_configuration(GoodJob.configuration, warm_cache_on_initialize: true) @notifier.recipients << [@scheduler, :create_thread] @poller.recipients << [@scheduler, :create_thread] - @cron_manager = GoodJob::CronManager.new(@configuration.cron_entries, start_on_initialize: true) if @configuration.enable_cron? + @cron_manager = GoodJob::CronManager.new(GoodJob.configuration.cron_entries, start_on_initialize: true) if GoodJob.configuration.enable_cron? @_async_started = true end # Whether the async executors are running