Search code examples
ruby-on-railsrubyresque

wrong number of arguments (given 1, expected 2) with Resque Worker


I understand the self.perform method needs two arguments and I am passing them in. I can assure you the instance variables have values because I have checked. What can you see am I doing wrong?

Controller:

Resque.enqueue_to(:high, SendInvitationEmail, user_token: @user.token, invitee_token: @invitee.token)

Worker:

class SendInvitationEmail
  def self.perform(user_token, invitee_token)
      Frontend::UserManagementMailer.invitation_email(user_token, invitee_token)
  end
end

Error:

wrong number of arguments (given 1, expected 2) line 3

Solution

  • The issue is that you're passing arguments to enqueue_to as keyword arguments or a Hash.

    Instead, remove the keys and pass the arguments as such.

    Resque.enqueue_to(:high, SendInvitationEmail, @user.token, @invitee.token)
    

    Or you could modify the method signature of perform to take in a hash or keyword arguments as

    class SendInvitationEmail
      def self.perform(user_token:, invitee_token:)
          Frontend::UserManagementMailer.invitation_email(user_token, invitee_token)
      end
    end