我正在尝试通过以下方式在我的规格范围内创建作业,但始终收到ArgumentError:-
MyJob.new.perform_now(user_id: @current_user.id, building_ids: [building.id])
module ActionPlan
class MyJob < ApplicationJob
queue_as :low
def perform(user_id:, building_ids:, **_args)
@user = User.find(user_id)
@buildings = ActionPlan::Reminder.where(user_id: user_id)
@buildings.map(&method(:create_alerts))
end
我不断收到wrong number of arguments (given 1, expected 0) (ArgumentError)
。我要去哪里错了? perform方法带有2个参数,对吗?我该如何调试?
答案 0 :(得分:1)
尝试一下:
module ActionPlan
class MyJob < ApplicationJob
queue_as :low
def initialize(user_id:, building_ids:, **_args)
@buildings = ActionPlan::Reminder.where(user_id: user_id)
end
def perform
buildings.map(&method(:create_alerts))
end
private
attr_accessor :buildings
end
end
那应该可以让您打电话:
MyJob.new(user_id: @current_user.id, building_ids: [building.id]).perform