【发布时间】:2014-08-15 14:46:54
【问题描述】:
我正在使用 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
我从控制器中调用 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
【问题讨论】:
-
你试过重启你的sidekiq守护进程吗?
-
是的,好几次。 ctrl + C 然后使用 $ bundle exec sidekiq 重新启动。几个小时以来一直在尝试修复它。
标签: ruby-on-rails ruby ruby-on-rails-4 sidekiq ruby-on-rails-4.1