aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/netex_import.rb
blob: a7a5bb9b88ca6f1483560308d32b5eb53f24196b (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
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
    Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}"))
  rescue Exception => e
    logger.error "IEV server error : #{e.message}"
    logger.error e.backtrace.inspect
  end

end