blob: b21af340833b21b268918a70171245b94ed5e74c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
require 'net/http'
class NetexImport < Import
before_destroy :destroy_non_ready_referential
after_commit :launch_java_import, on: :create
before_save def abort_unless_referential
self.status = 'aborted' unless referential
end
validates_presence_of :parent
def launch_java_import
return if self.class.finished_statuses.include?(status)
threaded_call_boiv_iev
end
private
def destroy_non_ready_referential
if referential && !referential.ready
referential.destroy
end
end
def threaded_call_boiv_iev
Thread.new(&method(:call_boiv_iev))
end
def call_boiv_iev
Rails.logger.error("Begin IEV call for import")
Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}"))
Rails.logger.error("End IEV call for import")
rescue Exception => e
logger.error "IEV server error : #{e.message}"
logger.error e.backtrace.inspect
end
end
|