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

Lock! Empty Resource Key Behavior (question) #123

Open
rypback opened this issue Feb 9, 2023 · 0 comments
Open

Lock! Empty Resource Key Behavior (question) #123

rypback opened this issue Feb 9, 2023 · 0 comments

Comments

@rypback
Copy link

rypback commented Feb 9, 2023

Hi there,

I have a method that may or may not need to lock based on a few conditions. I've tried moving all of that logic to a separate method which takes a few arguments. I can call that method directly with no problem, however, I'm unable to turn that method into a block to call lock! since the method takes args. If that's possible, I'd love to hear how.

But I was curious about the resource key. If that were to be conditionally set, either to a unique string or empty string/nil/etc. What would the behavior be? Would it lock on the unique string and not acquire a lock for the empty (which would be ideal). Or would there still be an acquired lock for ''.

Thanks for any insight you can provide.

Example:

class JobClass
  def perform
    if some_value == some_other_value
      return lock!('resource_key', ttl: 2000) do
        # How can I pass `run_job` with the args it needs to this block
      end
    end

    # This is the easy case (calling the run method directly)
    run_job(ActiveRecordInstance, '', 0)
  end

  def run_job(object, string, number)
    # critical code here
  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

1 participant