lib/good_job/adapter.rb in good_job-3.99.1 vs lib/good_job/adapter.rb in good_job-4.0.0
- old
+ new
@@ -35,11 +35,11 @@
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+
- # @return [GoodJob::Execution]
+ # @return [GoodJob::Job]
def enqueue(active_job)
enqueue_at(active_job, nil)
end
# Defines if enqueueing this job from inside an Active Record transaction
@@ -56,33 +56,22 @@
return 0 if active_jobs.empty?
Rails.application.executor.wrap do
current_time = Time.current
executions = active_jobs.map do |active_job|
- GoodJob::Execution.build_for_enqueue(active_job).tap do |execution|
- if GoodJob::Execution.discrete_support?
- execution.make_discrete
- execution.scheduled_at = current_time if execution.scheduled_at == execution.created_at
- end
-
- execution.created_at = current_time
- execution.updated_at = current_time
+ GoodJob::Job.build_for_enqueue(active_job).tap do |job|
+ job.scheduled_at = current_time if job.scheduled_at == job.created_at
+ job.created_at = current_time
+ job.updated_at = current_time
end
end
inline_executions = []
- GoodJob::Execution.transaction(requires_new: true, joinable: false) do
- execution_attributes = executions.map do |execution|
- if GoodJob::Execution.error_event_migrated?
- execution.attributes
- else
- execution.attributes.except('error_event')
- end
- end
+ GoodJob::Job.transaction(requires_new: true, joinable: false) do
+ execution_attributes = executions.map(&:attributes)
+ results = GoodJob::Job.insert_all(execution_attributes, returning: %w[id active_job_id]) # rubocop:disable Rails/SkipsModelValidations
- results = GoodJob::Execution.insert_all(execution_attributes, returning: %w[id active_job_id]) # rubocop:disable Rails/SkipsModelValidations
-
job_id_to_provider_job_id = results.each_with_object({}) { |result, hash| hash[result['active_job_id']] = result['id'] }
active_jobs.each do |active_job|
active_job.provider_job_id = job_id_to_provider_job_id[active_job.job_id]
active_job.successfully_enqueued = active_job.provider_job_id.present? if active_job.respond_to?(:successfully_enqueued=)
end
@@ -144,29 +133,29 @@
# Enqueues an ActiveJob job to be run at a specific time.
# For use by Rails; you should generally not call this directly.
# @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]
+ # @return [GoodJob::Job]
def enqueue_at(active_job, timestamp)
scheduled_at = timestamp ? Time.zone.at(timestamp) : nil
# If there is a currently open Bulk in the current thread, direct the
# job there to be enqueued using enqueue_all
return if GoodJob::Bulk.capture(active_job, queue_adapter: self)
Rails.application.executor.wrap do
will_execute_inline = execute_inline? && (scheduled_at.nil? || scheduled_at <= Time.current)
- will_retry_inline = will_execute_inline && CurrentThread.execution&.active_job_id == active_job.job_id && !CurrentThread.retry_now
+ will_retry_inline = will_execute_inline && CurrentThread.job&.active_job_id == active_job.job_id && !CurrentThread.retry_now
if will_retry_inline
- execution = GoodJob::Execution.enqueue(
+ execution = GoodJob::Job.enqueue(
active_job,
scheduled_at: scheduled_at
)
elsif will_execute_inline
- execution = GoodJob::Execution.enqueue(
+ execution = GoodJob::Job.enqueue(
active_job,
scheduled_at: scheduled_at,
create_with_advisory_lock: true
)
begin
@@ -184,10 +173,10 @@
execution.advisory_unlock
execution.run_callbacks(:perform_unlocked)
end
raise result.unhandled_error if result.unhandled_error
else
- execution = GoodJob::Execution.enqueue(
+ execution = GoodJob::Job.enqueue(
active_job,
scheduled_at: scheduled_at
)
executed_locally = execute_async? && @capsule&.create_thread(execution.job_state)