gpt4 book ai didi

ruby-on-rails - Sidekiq:perform_async 中的参数数量错误(4 对 3)错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:49:40 24 4
gpt4 key购买 nike

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

这是我的 worker 。

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

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

更新:

出现错误是因为在 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

最佳答案

试试这个:

notification_method_name = "assignment_notification"

NotificationWorker.perform_async(current_account_id, notification_method_name, resource_id)

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

关于ruby-on-rails - Sidekiq:perform_async 中的参数数量错误(4 对 3)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25328588/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com