sidekiq-unique-jobs icon indicating copy to clipboard operation
sidekiq-unique-jobs copied to clipboard

:replace is incompatible with the server process

Open chaimann opened this issue 3 years ago • 3 comments

Describe the bug Following the advice in https://github.com/mhenrixon/sidekiq-unique-jobs#unique-sidekiq-configuration I'm adding a similar test for my worker which uses :replace strategy on conflict. I'm getting an on_server_conflict: :replace is incompatible with the server process failed message, however I'm not sure what I'm expected to do here. ServerValidator has :replace strategy listed as invalid, but there's nothing about it in the documentation. Should I update my worker sidekiq options with strategies for both client and service? e.g.:

on_conflict: { client: :replace, server: :log }

Expected behavior I'd expect this behaviour to be described and explained in the documentation, especially which are the valid strategies for server/client and why.

Worker class

class MyWorker
  include Sidekiq::Worker
  sidekiq_options lock: :until_executed, on_conflict: :replace
end

Thanks!

chaimann avatar Apr 14 '21 14:04 chaimann

Yeah, the thing is, when this job has ended up on the server (meaning it was pushed by the client) it would be too late to replace the job.

Your suggested solution seems to do the trick. I actually wanted to force people to use on_conflict: { client: :replace, server: :log } already but it seemed cruel to make that part of the requirement for the upgrade to V7.

Some projects have hundreds of worker classes.

I'll get to the documentation as soon as I can, you are right in that it isn't good enough. It is just so hard with the limited time I have to improve it to what I'd like it to be.

mhenrixon avatar Apr 14 '21 14:04 mhenrixon

Thanks for the prompt reply :)

it would be too late to replace the job.

yeah that's what I was thinking too. And the on_conflict: { client: :replace, server: :log } helped with the test pass.

Also I didn't have time to check the code closely but interested what happens to the duplicate job once a unique one is already on the server and the strategy is :replace for both client and server - is the duplicate rejected silently?

Thanks for the work on this gem, I found it yesterday and even though documentation is not 100% complete the gem worked great for me so far and helped me with my current task!

chaimann avatar Apr 14 '21 16:04 chaimann

Sorry @chaimann, totally missed your last message.

Also I didn't have time to check the code closely but interested in what happens to the duplicate job once a unique one is already on the server and the strategy is :replace for both client and server - is the duplicate rejected silently?

No, in that situation, the job is replaced in the client middleware and then the server middleware crashes like you already discovered :)

mhenrixon avatar Jun 30 '21 19:06 mhenrixon