Reputation: 1011
I am using Rails(4.1.0) and Sidekiq(3.2.1) and acts_as_tenantInstalling (0.3.5)
Here is my 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
I am calling perform_async form 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
I am getting "wrong number of arguments (4 for 3)" from the line having sidekiq call in the controller. I have gone through documentation as well as other questions but can't figure out what i am doing wrong. Please help. Thanks.
Update:
The error was coming because of requiring sidekiq support in acts_as_tenant gem.
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
Upvotes: 3
Views: 1953