Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Que::ActiveRecord::Model.by_args incompatible with ActiveJob JobWrapper #358

Open
milgner opened this issue Apr 13, 2022 · 2 comments
Open

Comments

@milgner
Copy link

milgner commented Apr 13, 2022

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
Copy link
Member

ZimbiX commented Apr 13, 2022

Ah, good find

@ronald
Copy link

ronald commented Jun 3, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants