Update ActiveJob que adapter for compatibility

que 1.2 introduced a deprecation warning when specifying job options
directly within the `#enqueue` method. From 1.2 job options need to be
provided as a hash in `job_options` keyword argument.

que 1.x is not compatible with Ruby 3 yet. que 2 will be.

This commit resolves the deprecation warning and ensures future
compatibility with que 2, allowing path to Ruby 3 upgrade preserving
compatibility with que 1.0.

Co-authored-by: Adis Hasović <adis@80pct.com>
This commit is contained in:
Damir Zekić 2022-03-21 13:19:25 +01:00
parent b764fc24c8
commit 6c93373842
1 changed files with 28 additions and 6 deletions

View File

@ -18,22 +18,44 @@ module ActiveJob
# Rails.application.config.active_job.queue_adapter = :que
class QueAdapter
def enqueue(job) # :nodoc:
que_job = JobWrapper.enqueue job.serialize, priority: job.priority, queue: job.queue_name
job_options = { priority: job.priority, queue: job.queue_name }
que_job = nil
if require_job_options_kwarg?
que_job = JobWrapper.enqueue job.serialize, job_options: job_options
else
que_job = JobWrapper.enqueue job.serialize, **job_options
end
job.provider_job_id = que_job.attrs["job_id"]
que_job
end
def enqueue_at(job, timestamp) # :nodoc:
que_job = JobWrapper.enqueue job.serialize, priority: job.priority, queue: job.queue_name, run_at: Time.at(timestamp)
job_options = { priority: job.priority, queue: job.queue_name, run_at: Time.at(timestamp) }
que_job = nil
if require_job_options_kwarg?
que_job = JobWrapper.enqueue job.serialize, job_options: job_options
else
que_job = JobWrapper.enqueue job.serialize, **job_options
end
job.provider_job_id = que_job.attrs["job_id"]
que_job
end
class JobWrapper < Que::Job # :nodoc:
def run(job_data)
Base.execute job_data
private
def require_job_options_kwarg?
@require_job_options_kwarg ||=
JobWrapper.method(:enqueue).parameters.any? { |ptype, pname| ptype == :key && pname == :job_options }
end
class JobWrapper < Que::Job # :nodoc:
def run(job_data)
Base.execute job_data
end
end
end
end
end
end