Resque Worker 的参数数量错误(给定 1,预期 2)

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

我知道 self.perform 方法需要两个参数,我正在传递它们。我可以向你保证实例变量有值,因为我已经检查过了。你能看出我做错了什么吗?

控制器:

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

工人:

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

错误:

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

问题是您将参数作为关键字参数或 Hash.

传递给 enqueue_to

取而代之的是,删除键并按原样传递参数。

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

或者您可以修改 perform 的方法签名以将散列或关键字参数作为

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