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

Because replace is a client strategy, it should only remove client locks aka queue locks. #778

Conversation

bigzed
Copy link
Contributor

@bigzed bigzed commented Apr 27, 2023

I just tried to use replace with until_and_while_executing and noticed, that when I spam TheLockedJob.perform_async(1) it would replace the job in the queue and also delete the runtime lock of the already running job leading to two jobs running at the same time.

The change results in the job correctly being replaced on the queue without removing existing runtime locks for the job.

result, elapsed = timed do
queue = queuetime ? digest : ""
queue_queued = queuetime ? "#{digest}:QUEUED" : ""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still thinking about this, I get the problem, but wondering if there is a better way.

The code ended up being a little repetitive below. Perhaps we could just have two other methods:

  1. queuetime_keys
  2. runtime_keys
keys = []
keys.concat(queuetime_keys)
keys.concat(runtime_keys)

call_script(:delete_by_digest, keys)

EMPTY_KEYS_SEGMENT = ["", "", "", ""].freeze

def queuetime_keys(queuetime)
  return EMPTY_KEYS_SEGMENT unless queuetime
  
  [
    digest,
    "#{digest}:QUEUED",
    "#{digest}:PRIMED",
    "#{digest}:LOCKED",  
  ]
end

What do you think? I find the code a little harsh on the eyes. Do you know any better way (than mine) to construct the array to send to the script (the keys) I'm all ears and eyes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I refactored the code a little and created the two helper methods. WDYT?

Cleaning up `Digests#delete_by_digest`. Instead of assembling all keys
inside of the method, we introduced a const and two helper methods to
make the code easier on the eyes.
@bigzed bigzed force-pushed the fix-replace-for-until-and-while-executing branch from 232f6ea to 96939ce Compare July 27, 2023 14:10
Copy link
Owner

@mhenrixon mhenrixon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome. If you ensure that Reek passes, I'll release it!

@mhenrixon mhenrixon merged commit c6a4138 into mhenrixon:main Nov 11, 2023
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

Successfully merging this pull request may close these issues.

2 participants