blob: a4bf0920d7f8ee4eb385973f0cfc710c768a1683 (
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 Import::Netex < Import::Base
  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
 |