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

Not compatible with resque-status #40

Open
ghost opened this issue Aug 13, 2014 · 1 comment
Open

Not compatible with resque-status #40

ghost opened this issue Aug 13, 2014 · 1 comment

Comments

@ghost
Copy link

ghost commented Aug 13, 2014

Resque-loner does not work when also using the resque-status plugin since the latter adds a job_id to the payload and so that confuses resque-loner into thinking that the job does not already exist and thus allows. I am not sure there’s much to do about this but I’m just opening this ticket as a reference for others.

For now, I’m trying to work around the issue by monkey patching the redis_key function to remove the job_id from the payload before calculating the md5 hash.

Here’s the code:

# Monkey patch resque-loner so that it plays ball with resque-status.
module Resque
  module Plugins
    module UniqueJob
      module ClassMethods
        def redis_key(payload)
          payload = decode(encode(payload)) # This is the cycle the data goes when being enqueued/dequeued
          job  = payload[:class] || payload['class']
          args = (payload[:args]  || payload['args'])

          # This is a quick hack so that this library works with resque-status.
          # Resque-status adds a job_id as the first element of args, and this
          # messes up how resque-loner determines if a job is already queued or
          # not. By removing the job_id, everything should be A-OK. Only workers
          # that include resque-loner should be affected. Small caveat, when calling
          # Resque.enqueued? that comes with resque-loner, there’s no job_id to
          # remove so we must do nothing in that case.
          if respond_to?(:create)
            args.shift unless caller.index { |e| e =~ /enqueued\?/ }
          end

          args.map! do |arg|
            arg.is_a?(Hash) ? arg.sort : arg
          end

          digest = Digest::MD5.hexdigest(encode(class: job, args: args))
          digest
        end
      end
    end
  end
end
@jchatel
Copy link

jchatel commented Dec 17, 2015

Still the case in end of 2015 unfortunately.

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