Que::ActiveRecord::Model.by_args incompatible with ActiveJob JobWrapper
milgner opened this issue · 2 comments
milgner commented
While Que::ActiveRecord::Model.by_job_class
already takes the presence of the job wrapper into account, there is no such provision in .by_args
.
After looking at the implementation I was able to successfully query for the presence of a job using partial positional arguments in my application using
.by_args({'arguments' => [{ 'event_id' => important_event_id }]})
but I haven't familiarised myself with the conversion of keyword arguments for the JobWrapper
yet so I'm not sure what the correct solution would be for that scenario.
Also, Que::Sequel::Model
might need similar adaptations, but I haven't checked that out either.
ZimbiX commented
Ah, good find
ronald commented
class QueJob < Que::ActiveRecord::Model
def self.by_args(*args, **kwargs)
# que's version:
# where("que_jobs.args @> ? AND que_jobs.kwargs @> ?", JSON.dump(args), JSON.dump(kwargs))
args_json = JSON.dump(args)
where("(que_jobs.args @> ? OR (que_jobs.job_class = 'ActiveJob::QueueAdapters::QueAdapter::JobWrapper' AND que_jobs.args->0#>'{arguments}' @> ?))
AND que_jobs.kwargs @> ?", args_json, args_json, JSON.dump(kwargs))
end
end