Sidekiq:perform_async中的参数数量错误(4个为3)错误

时间:2014-08-15 14:46:54

标签: ruby-on-rails ruby ruby-on-rails-4 sidekiq ruby-on-rails-4.1

我正在使用Rails(4.1.0)和Sidekiq(3.2.1)以及acts_as_tenantInstalling(0.3.5)

这是我的工作人员。

class NotificationWorker
  include Sidekiq::Worker

  sidekiq_options retry: false

  def perform(current_account_id, notification_method_name, resource_id)
    current_account = Account.find(current_account_id)

    # Prcocess only if current account is not nil
    if current_account.present?
        ActsAsTenant.with_tenant(current_account) do
          # Current tenant is set for all code in this block
            notification_service = NotificationService.new
            notification_service.method(notification_method_name).call(resource_id)
        end
    end
  end
end

我正在调用perform_async表单assignments_controller。

  def create
    @assignment = Assignment.new(assignment_params)

    respond_to do |format|
      if @assignment.save
        current_account_id = current_tenant.id
        resource_id = @assignment.id
        NotificationWorker.perform_async(current_account_id, "assignment_notification", resource_id)
        format.html { redirect_to @assignment, notice: 'Assignment was successfully created.' }
        format.json { render :show, status: :created, location: @assignment }
      else
        format.html { render :new }
        format.json { render json: @assignment.errors, status: :unprocessable_entity }
      end
    end
  end

我得到了错误的论点数(4个为3个)"从控制器中有sidekiq调用的行。我已经阅读了文档以及其他问题,但无法弄清楚我做错了什么。请帮忙。感谢。

更新

由于在acts_as_tenant gem中需要sidekiq支持,因此出现错误。

ActsAsTenant.configure do |config|
  #ActsAsTenant supports Sidekiq. A background processing library.
  require 'acts_as_tenant/sidekiq'

  # When set to true will raise an ActsAsTenant::NoTenant error, whenever 
  # a query is made without a tenant set.   
  config.require_tenant = false # true

end

1 个答案:

答案 0 :(得分:0)

试试这个:

notification_method_name = "assignment_notification"

NotificationWorker.perform_async(current_account_id, notification_method_name, resource_id)

或许您可以尝试使用符号,例如here