aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tasks/exports.rake
diff options
context:
space:
mode:
authorZog2018-03-02 11:17:08 +0100
committerZog2018-03-02 11:17:08 +0100
commitc1ac12174b9aff7535a84af9f76d1cda95b750f4 (patch)
tree1207cd5a338cb9d7868bb893a50ef19978515b54 /lib/tasks/exports.rake
parent6e694fb2d88fe29049ecf5bb3d0e89e0585bf6c5 (diff)
downloadchouette-core-c1ac12174b9aff7535a84af9f76d1cda95b750f4.tar.bz2
Refs #6068; Refactor import/export tasks
Diffstat (limited to 'lib/tasks/exports.rake')
-rw-r--r--lib/tasks/exports.rake47
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/tasks/exports.rake b/lib/tasks/exports.rake
new file mode 100644
index 000000000..036d96b11
--- /dev/null
+++ b/lib/tasks/exports.rake
@@ -0,0 +1,47 @@
+require 'csv'
+require 'tasks/helpers/simple_interfaces'
+
+namespace :export 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 "export companies in the give LineReferential using the given exporter"
+ task :companies, [:referential_id, :configuration_name, :filepath, :logs_output_dir] => :environment do |t, args|
+ args.with_defaults(filepath: "./companies.csv", logs_output_dir: "./log/exporters/")
+ FileUtils.mkdir_p args[:logs_output_dir]
+
+ referential = LineReferential.find args[:referential_id]
+ exporter = SimpleExporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
+ exporter.configure do |config|
+ config.collection = referential.companies.order(:name)
+ end
+
+ SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args
+ end
+
+ desc "export lines in the give LineReferential using the given exporter"
+ task :lines, [:referential_id, :configuration_name, :filepath, :logs_output_dir] => :environment do |t, args|
+ args.with_defaults(filepath: "./companies.csv", logs_output_dir: "./log/exporters/")
+ FileUtils.mkdir_p args[:logs_output_dir]
+
+ referential = LineReferential.find args[:referential_id]
+ exporter = SimpleExporter.create configuration_name: args[:configuration_name], filepath: args[:filepath]
+ exporter.configure do |config|
+ config.collection = referential.lines.order(:name)
+ end
+
+ SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args
+ end
+
+ desc "export a complete offer from the gicen referential in the given X next days"
+ task :full_offer, [:referential_id, :timelapse, :configuration_name, :output_dir, :logs_output_dir] => :environment do |t, args|
+ args.with_defaults(filepath: "./companies.csv", logs_output_dir: "./log/exporters/")
+ end
+end