Skip to content

Not compatible with resque-status #40

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions