Я использую Rails (4.1.0) и Sidekiq (3.2.1) и act_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
Я звоню в форму execute_asyncassigns_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 в контроллере. Я просмотрел документацию, а также другие вопросы, но не могу понять, что я делаю неправильно. Пожалуйста помоги. Спасибо.
Обновлять:
Ошибка возникала из-за необходимости поддержки sidekiq в геме act_as_tenant.
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