Skip to content

Commit

Permalink
move some logic to background job
Browse files Browse the repository at this point in the history
  • Loading branch information
tvcam committed Aug 25, 2023
1 parent a9def4b commit 667eb1f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
8 changes: 4 additions & 4 deletions app/controllers/api/v1/organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def clients
end

def create
if org = Organization.create_and_build_tenant(organization_params)
OrganizationWorker.perform_async(org.id, org.referral_source_category_name)
org = Organization.new(organization_params)
if org.save
OrganizationWorker.perform_async(org.id)

render json: org, status: :ok
else
render json: { msg: org.errors }, status: :unprocessable_entity
end
rescue => e
render json: e.message, status: :unprocessable_entity
end

def upsert
Expand Down
7 changes: 5 additions & 2 deletions app/workers/organization_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ class OrganizationWorker
include Sidekiq::Worker
sidekiq_options queue: 'priority'

def perform(org_id, referral_source_category_name)
Organization.seed_generic_data(org_id, referral_source_category_name)
def perform(org_id)
organization = Organization.find(org_id)

Apartment::Tenant.create(organization.short_name)
Organization.seed_generic_data(organization.id, organization.referral_source_category_name)
end
end

0 comments on commit 667eb1f

Please sign in to comment.