lib/good_job/adapter.rb in good_job-2.99.0 vs lib/good_job/adapter.rb in good_job-3.0.0
- old
+ new
@@ -18,36 +18,20 @@
# When not in the Rails web server, jobs will execute in +:external+ mode to ensure jobs are not executed within `rails console`, `rails db:migrate`, `rails assets:prepare`, etc.
# - +:async_all+ executes jobs in any Rails process.
#
# The default value depends on the Rails environment:
#
- # - +development+ and +test+: +:inline+
+ # - +development+: +:async:+
+ # -+test+: +:inline+
# - +production+ and all other environments: +:external+
#
- # @param max_threads [Integer, nil] sets the number of threads per scheduler to use when +execution_mode+ is set to +:async+. The +queues+ parameter can specify a number of threads for each group of queues which will override this value. You can also set this with the environment variable +GOOD_JOB_MAX_THREADS+. Defaults to +5+.
- # @param queues [String, nil] determines which queues to execute jobs from when +execution_mode+ is set to +:async+. See {file:README.md#optimize-queues-threads-and-processes} for more details on the format of this string. You can also set this with the environment variable +GOOD_JOB_QUEUES+. Defaults to +"*"+.
- # @param poll_interval [Integer, nil] sets the number of seconds between polls for jobs when +execution_mode+ is set to +:async+. You can also set this with the environment variable +GOOD_JOB_POLL_INTERVAL+. Defaults to +1+.
- # @param start_async_on_initialize [Boolean] whether to start the async scheduler when the adapter is initialized.
- def initialize(execution_mode: nil, queues: nil, max_threads: nil, poll_interval: nil, start_async_on_initialize: nil)
- if queues || max_threads || poll_interval || start_async_on_initialize
- ActiveSupport::Deprecation.warn(
- "GoodJob::Adapter's execution-related arguments (queues, max_threads, poll_interval, start_async_on_initialize) have been deprecated and will be removed in GoodJob v3. These options should be configured through GoodJob global configuration instead."
- )
- end
-
- @configuration = GoodJob::Configuration.new(
- {
- execution_mode: execution_mode,
- queues: queues,
- max_threads: max_threads,
- poll_interval: poll_interval,
- }
- )
+ def initialize(execution_mode: nil)
+ @configuration = GoodJob::Configuration.new({ execution_mode: execution_mode })
@configuration.validate!
self.class.instances << self
- start_async if start_async_on_initialize || GoodJob.async_ready?
+ 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.
# @param active_job [ActiveJob::Base] the job to be enqueued from +#perform_later+
@@ -61,45 +45,18 @@
# @param active_job [ActiveJob::Base] the job to be enqueued from +#perform_later+
# @param timestamp [Integer, nil] the epoch time to perform the job
# @return [GoodJob::Execution]
def enqueue_at(active_job, timestamp)
scheduled_at = timestamp ? Time.zone.at(timestamp) : nil
+ will_execute_inline = execute_inline? && (scheduled_at.nil? || scheduled_at <= Time.current)
- if execute_inline?
- future_scheduled = scheduled_at && scheduled_at > Time.current
- will_execute_inline = !future_scheduled || (future_scheduled && !@configuration.inline_execution_respects_schedule?)
- end
-
execution = GoodJob::Execution.enqueue(
active_job,
scheduled_at: scheduled_at,
create_with_advisory_lock: will_execute_inline
)
if will_execute_inline
- if future_scheduled && !@configuration.inline_execution_respects_schedule?
- ActiveSupport::Deprecation.warn(<<~DEPRECATION)
- In the next major release, GoodJob will not *inline* execute
- future-scheduled jobs.
-
- To opt into this behavior immediately set:
- `config.good_job.inline_execution_respects_schedule = true`
-
- To perform jobs inline at any time, use `GoodJob.perform_inline`.
-
- For example, using time helpers within an integration test:
-
- ```
- MyJob.set(wait: 10.minutes).perform_later
- travel_to(15.minutes.from_now) { GoodJob.perform_inline }
- ```
-
- Note: Rails `travel`/`travel_to` time helpers do not have millisecond
- precision, so you must leave at least 1 second between the schedule
- and time traveling for the job to be executed.
- DEPRECATION
- end
-
begin
result = execution.perform
ensure
execution.advisory_unlock
end