exq icon indicating copy to clipboard operation
exq copied to clipboard

:fake mode does not respect uniqueness settings

Open nicnilov opened this issue 1 year ago • 3 comments

Here is an example:

args = ["arg1", "arg2"]
unique_token = "my_unique_token"

Exq.enqueue(Exq, "queue", MyWorker, args, unique_token: unique_token, unique_for: 5)
Exq.enqueue(Exq, "queue", MyWorker, args, unique_token: unique_token, unique_for: 5)
Exq.enqueue(Exq, "queue", MyWorker, args, unique_token: unique_token, unique_for: 5)

Expected result: A single instance of the job is returned by Exq.Mock.jobs(). Actual result: Three instances of the job get returned by Exq.Mock.jobs().

Additionally, the returned jobs have their uniqueness attributes set to nil while it might be expected those would carry at least some of the supplied values:

[
  %Exq.Support.Job{
    error_message: nil,
    error_class: nil,
    retried_at: nil,
    failed_at: nil,
    retry: false,
    retry_count: 0,
    processor: nil,
    queue: "queue",
    class: MyWorker,
    args: ["arg1", "arg2"],
    jid: "7789467e-dc08-4af4-a006-6ad9e5113f21",
    finished_at: nil,
    enqueued_at: ~U[2024-07-08 11:31:22.577966Z],
    unique_for: nil,
    unique_until: nil,
    unique_token: nil,
    unlocks_at: nil
  },
  ...
]

Exq config:

In config/config.exs:

config :exq,
  name: Exq,
  ...
  middleware: [Exq.Middleware.Stats, Exq.Middleware.Job, Exq.Middleware.Manager,
               Exq.Middleware.Unique, Exq.Middleware.Logger]

In config/test.exs:

config :exq,
  queue_adapter: Exq.Adapters.Queue.Mock,
  start_on_application: false

In test_helper.exs:

Exq.Mock.start_link(mode: :fake)

Changing the Mock config to mode: :inline correctly enqueues just a single instance of worker.

nicnilov avatar Jul 08 '24 12:07 nicnilov

This is one of those things that is not supported by a fake adapter. I am surprised inline is working, only Redis adapter is supposed to work correctly.

ananthakumaran avatar Jul 08 '24 12:07 ananthakumaran

Is this by design then and not going to be fixed?

nicnilov avatar Jul 08 '24 14:07 nicnilov

Sorry, looks like I missed the reply. It's not by design, just that we didn't get around to implementing it. PRs are welcome.

ananthakumaran avatar May 05 '25 15:05 ananthakumaran