Skip to content

Commit 33c9d56

Browse files
bitboxersalimhb
andauthored
Add locations to IRIS index (#128)
* Add locations to IRIS index closes railslove/recover-backlog#128 * add proxy configuration for rest-client * move jimson gem to use on production * start processes using tunnel * Revert "start processes using tunnel" This reverts commit 1a688ed. Co-authored-by: salimhb <[email protected]> Co-authored-by: salimhb <[email protected]>
1 parent 1861849 commit 33c9d56

File tree

11 files changed

+129
-1
lines changed

11 files changed

+129
-1
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ DEVISE_JWT_SECRET_KEY=9dde7c3cebc4c85e91a6f6e520b683396cd4f0d218671f4f2a398f2b6f
1919
# STRIPE_TAX_RATE_ID=
2020
#
2121
# FRONTEND_URL=
22+
# IRIS_EPS_URL=

.env.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
STRIPE_SUBSCRIPTION_PRICE_ID=test_price
2-
HAPPY_PDF_API_KEY=HAPPY_KEY
2+
HAPPY_PDF_API_KEY=HAPPY_KEY
3+
IRIS_EPS_URL=https://localhost:5556/jsonrpc

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ gem 'activestorage-validator'
2222
gem 'image_processing'
2323
gem 'paper_trail'
2424
gem 'protobuf'
25+
gem 'jimson'
2526

2627
# Emails
2728
gem 'mailgun-ruby', '~> 1.2'

Gemfile.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ GEM
9393
aws-sigv4 (1.2.3)
9494
aws-eventstream (~> 1, >= 1.0.2)
9595
bcrypt (3.1.16)
96+
blankslate (3.1.3)
9697
bootsnap (1.7.5)
9798
msgpack (~> 1.0)
9899
builder (3.2.4)
@@ -181,6 +182,11 @@ GEM
181182
interactor-rails (2.2.1)
182183
interactor (~> 3.0)
183184
rails (>= 4.2)
185+
jimson (0.13.0)
186+
blankslate (>= 3.1.3)
187+
multi_json (>= 1.11.2)
188+
rack (>= 1.4.5)
189+
rest-client (>= 1.7.3)
184190
jmespath (1.4.0)
185191
jquery-rails (4.4.0)
186192
rails-dom-testing (>= 1, < 3)
@@ -226,6 +232,7 @@ GEM
226232
mini_portile2 (2.5.1)
227233
minitest (5.14.4)
228234
msgpack (1.4.2)
235+
multi_json (1.15.0)
229236
multi_xml (0.6.0)
230237
multipart-post (2.1.1)
231238
nested_form (0.3.2)
@@ -423,6 +430,7 @@ DEPENDENCIES
423430
image_processing
424431
inky-rb
425432
interactor-rails
433+
jimson
426434
letter_opener
427435
listen (~> 3.5)
428436
mailgun-ruby (~> 1.2)

app/jobs/iris_delete_company.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class IrisDeleteCompany < ApplicationJob
2+
queue_as :default
3+
4+
def perform(company_id)
5+
return if ENV["IRIS_EPS_URL"].blank?
6+
Jimson::Client.new(
7+
ENV["IRIS_EPS_URL"], {id_type: :string}, "ls-1.", {verify_ssl: false}
8+
).deleteLocationFromSearchIndex({
9+
locationId: company_id
10+
})
11+
end
12+
end

app/jobs/iris_update_company.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
class IrisUpdateCompany < ApplicationJob
2+
queue_as :default
3+
4+
def perform(company_id)
5+
return if ENV["IRIS_EPS_URL"].blank?
6+
7+
company = Company.find(company_id)
8+
return unless company
9+
10+
Jimson::Client.new(
11+
ENV["IRIS_EPS_URL"], {id_type: :string}, "ls-1.", {verify_ssl: false}
12+
).postLocationsToSearchIndex({
13+
locations: [
14+
{
15+
id: company.id,
16+
name: company.name,
17+
contact: {
18+
officalName: company.name,
19+
representative: company.owner.name,
20+
address: {
21+
street: company.street,
22+
city: company.city,
23+
zip: company.zip
24+
},
25+
email: company.owner.email,
26+
phone: company.owner.phone
27+
}
28+
}
29+
]
30+
})
31+
end
32+
end

app/models/company.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ class Company < ApplicationRecord
5656
menu_pdf.purge if remove_menu_pdf == '1' and menu_pdf.attached?
5757
}
5858

59+
after_commit(on: [:create, :update]) {
60+
IrisUpdateCompany.perform_later(self.id)
61+
}
62+
63+
after_commit(on: [:destroy]) {
64+
IrisDeleteCompany.perform_later(self.id)
65+
}
66+
5967
def menu_pdf_link
6068
return unless menu_pdf.attached?
6169

config/initializers/rest-client.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require "rest-client"
2+
3+
RestClient.proxy = ENV["QUOTAGUARDSTATIC_URL"] if ENV["QUOTAGUARDSTATIC_URL"].present?

spec/jobs/iris_delete_company_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
require 'rails_helper'
2+
3+
RSpec.describe IrisDeleteCompany, type: :job do
4+
5+
it "should send a delete request via JSON-RPC" do
6+
company = FactoryBot.create(:company)
7+
expect_any_instance_of(Jimson::ClientHelper).to receive(:process_call).with(:deleteLocationFromSearchIndex, {
8+
locationId: company.id
9+
})
10+
IrisDeleteCompany.perform_now(company.id)
11+
end
12+
end

spec/jobs/iris_update_company_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
require 'rails_helper'
3+
4+
RSpec.describe IrisUpdateCompany, type: :job do
5+
6+
it "should send a update request via JSON-RPC" do
7+
company = FactoryBot.create(:company)
8+
expect_any_instance_of(Jimson::ClientHelper).to receive(:process_call).with(:postLocationsToSearchIndex, {
9+
locations: [
10+
{
11+
id: company.id,
12+
name: company.name,
13+
contact: {
14+
officalName: company.name,
15+
representative: company.owner.name,
16+
address: {
17+
street: company.street,
18+
city: company.city,
19+
zip: company.zip
20+
},
21+
email: company.owner.email,
22+
phone: company.owner.phone
23+
}
24+
}
25+
]
26+
})
27+
IrisUpdateCompany.perform_now(company.id)
28+
end
29+
end

0 commit comments

Comments
 (0)