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

- old
+ new

@@ -8,12 +8,10 @@ # @!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. @@ -25,14 +23,14 @@ # - +development+: +:async:+ # -+test+: +:inline+ # - +production+ and all other environments: +:external+ # def initialize(execution_mode: nil) - @execution_mode = (execution_mode || GoodJob.configuration.execution_mode).to_sym - GoodJob::Configuration.validate_execution_mode(@execution_mode) - self.class.instances << self + @_execution_mode_override = execution_mode + GoodJob::Configuration.validate_execution_mode(@_execution_mode_override) if @_execution_mode_override + self.class.instances << self start_async if GoodJob.async_ready? end # Enqueues the ActiveJob job to be performed. # For use by Rails; you should generally not call this directly. @@ -92,20 +90,27 @@ executables = [@notifier, @poller, @scheduler].compact GoodJob._shutdown_all(executables, timeout: timeout) @_async_started = false end + # This adapter's execution mode + # @return [Symbol, nil] + def execution_mode + @_execution_mode_override || GoodJob.configuration.execution_mode + end + # Whether in +:async+ execution mode. # @return [Boolean] def execute_async? execution_mode == :async_all || (execution_mode.in?([:async, :async_server]) && in_server_process?) end # Whether in +:external+ execution mode. # @return [Boolean] def execute_externally? - execution_mode == :external || + execution_mode.nil? || + execution_mode == :external || (execution_mode.in?([:async, :async_server]) && !in_server_process?) end # Whether in +:inline+ execution mode. # @return [Boolean]