aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks/imports.rake
blob: e1043106e4d8fa9ae195f0532b747e79a1795dc5 (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
namespace :import do
  desc "Notify parent imports when children finish"
  task notify_parent: :environment do
    ParentNotifier.new(Import).notify_when_finished
  end

  desc "Mark old unfinished Netex imports as 'aborted'"
  task netex_abort_old: :environment do
    NetexImport.abort_old
  end

  desc "import the given file with the corresponding importer"
  task :import, [:configuration_name, :filepath] => :environment do |t, args|
    importer = SimpleImporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
    puts "\e[33m***\e[0m Start importing"
    importer.import(verbose: true)
    puts "\n\e[33m***\e[0m Import done, status: " + (importer.status == "success" ? "\e[32m" : "\e[31m" ) + importer.status + "\e[0m"
  end

  desc "import the given file with the corresponding importer in the given StopAreaReferential"
  task :import_stop_areas_in_referential, [:referential_id, :configuration_name, :filepath] => :environment do |t, args|
    referential = StopAreaReferential.find args[:referential_id]
    importer = SimpleImporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
    importer.configure do |config|
      config.add_value :stop_area_referential, referential
      config.context = {stop_area_referential: referential}
    end
    puts "\e[33m***\e[0m Start importing"
    importer.import(verbose: true)
    puts "\n\e[33m***\e[0m Import done, status: " + (importer.status == "success" ? "\e[32m" : "\e[31m" ) + importer.status + "\e[0m"
  end
end