diff options
Diffstat (limited to 'lib/tasks')
| -rw-r--r-- | lib/tasks/ci.rake | 26 | ||||
| -rw-r--r-- | lib/tasks/erd.rake | 6 | ||||
| -rw-r--r-- | lib/tasks/exports.rake | 19 | ||||
| -rw-r--r-- | lib/tasks/helpers/simple_interfaces.rb | 19 | ||||
| -rw-r--r-- | lib/tasks/imports.rake | 6 |
5 files changed, 40 insertions, 36 deletions
diff --git a/lib/tasks/ci.rake b/lib/tasks/ci.rake index 89f9aa9c8..5b2c8ae3c 100644 --- a/lib/tasks/ci.rake +++ b/lib/tasks/ci.rake @@ -1,9 +1,18 @@ namespace :ci do + + def database_name + @database_name ||= + begin + config = YAML.load(ERB.new(File.read('config/database.yml')).result) + config["test"]["database"] + end + end + desc "Prepare CI build" task :setup do - cp "config/database/jenkins.yml", "config/database.yml" + cp "config/database/ci.yml", "config/database.yml" + puts "Use #{database_name} database" sh "RAILS_ENV=test rake db:drop db:create db:migrate" - sh "yarn --no-progress install" end def git_branch @@ -59,7 +68,18 @@ namespace :ci do sh "rm -rf log/test.log" sh "RAILS_ENV=test bundle exec rake assets:clobber" end + + task :build => ["ci:setup", "ci:assets", "ci:i18n_js_export", "spec", "ci:jest", "cucumber", "ci:check_security"] + + namespace :docker do + task :clean do + puts "Drop #{database_name} database" + sh "RAILS_ENV=test rake db:drop" + end + end + + task :docker => ["ci:build"] end desc "Run continuous integration tasks (spec, ...)" -task :ci => ["ci:setup", "ci:assets", "ci:i18n_js_export", "spec", "ci:jest", "cucumber", "ci:check_security", "ci:deploy", "ci:clean"] +task :ci => ["ci:build", "ci:deploy", "ci:clean"] diff --git a/lib/tasks/erd.rake b/lib/tasks/erd.rake index 96bb7fe37..b5790a9ab 100644 --- a/lib/tasks/erd.rake +++ b/lib/tasks/erd.rake @@ -5,11 +5,11 @@ namespace :generate do sh "bundle exec rake erd only='Organisation,Referential,User,Workbench,Workgroup' filename='organisation' title='Organisation'" sh "bundle exec rake erd only='Calendar,Referential,ReferentialMetadata,Chouette::Line,Chouette::Route,Chouette::JourneyPattern,Chouette::VehicleJourney,Chouette::VehicleJourneyAtStop,Chouette::TimeTable,Chouette::TimeTableDate,Chouette::TimeTablePeriod,Chouette::Footnote,Chouette::Network,Chouette::Company,Chouette::StopPoint,Chouette::StopArea' filename='offer_datas' title='Offer Datas'" sh "bundle exec rake erd only='Organisation,StopAreaReferential,StopAreaReferentialSync,StopAreaReferentialSyncMessage,StopAreaReferentialMembership,LineReferential,LineReferentialSync,LineReferentialSyncMessage,LineReferentialMembership' filename='referentiels_externes' title='Référentiels externes'" - sh "bundle exec rake erd only='NetexImport,Import,WorkbenchImport,ImportResource,ImportMessage' filename='import' title='Import'" + sh "bundle exec rake erd only='Import::Netex,Import::Base,Import::Workbench,Import::Resource,Import::Message' filename='import' title='Import'" sh "bundle exec rake erd only='ComplianceControlSet,ComplianceControlBlock,ComplianceControl,ComplianceCheckSet,ComplianceCheckBlock,ComplianceCheck,ComplianceCheckResource,ComplianceCheckMessage' filename='validation' title='Validation'" sh "bundle exec rake erd only='Organisation,Workgroup,Workbench,ReferentialSuite,Referential' filename='merge' title='Merge'" - #sh "bundle exec rake erd only='VehicleJourney,VehicleJourneyExport' filename='export' title='Export'" - #sh "bundle exec rake erd only='' filename='integration' title='Integration'" + sh "bundle exec rake erd only='Export::Base,Export::Message,Export::Resource,Export::Workgroup' filename='export' title='Export'" + sh "bundle exec rake erd only='Workbench,Referential,ReferentialSuite,Merge' filename='merge' title='Merge'" #sh "bundle exec rake erd only='' filename='publication' title='Publication'" end diff --git a/lib/tasks/exports.rake b/lib/tasks/exports.rake index 547388b35..845d581d3 100644 --- a/lib/tasks/exports.rake +++ b/lib/tasks/exports.rake @@ -51,6 +51,9 @@ namespace :export do if journeys.count == 0 puts "No maching journeys were found".red else + exports_group = SimpleInterfacesGroup.new "Export Complet \"#{referential.name}\" du #{Time.now.to_date} au #{args[:timelapse].to_i.days.from_now.to_date}" + exports_group.shared_options = {verbose: true} + exporter = SimpleJsonExporter.create configuration_name: "#{args[:configuration_name]}_companies", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_companies.json" ids = journeys.pluck :company_id ids += journeys.joins(route: :line).pluck :"lines.company_id" @@ -59,39 +62,37 @@ namespace :export do config.collection = Chouette::Company.where(id: ids.uniq).order('name') end - SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args - break if exporter.status == :error + exports_group.add_interface exporter, "Services Types", :export exporter = SimpleJsonExporter.create configuration_name: "#{args[:configuration_name]}_schedules", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_schedules.json" exporter.configure do |config| config.collection = journeys end - SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args - break if exporter.status == :error + exports_group.add_interface exporter, "Schedules", :export exporter = SimpleJsonExporter.create configuration_name: "#{args[:configuration_name]}_routes", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_routes.json" exporter.configure do |config| config.collection = Chouette::JourneyPattern.where(id: journeys.pluck(:journey_pattern_id).uniq) end - SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args - break if exporter.status == :error + exports_group.add_interface exporter, "Routes", :export exporter = SimpleJsonExporter.create configuration_name: "#{args[:configuration_name]}_stops", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_stops.json" exporter.configure do |config| config.collection = Chouette::StopArea.where(id: journeys.joins(:stop_points).pluck(:"stop_points.stop_area_id").uniq).order('parent_id ASC NULLS FIRST') end - SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args - break if exporter.status == :error + exports_group.add_interface exporter, "Stops", :export exporter = SimpleJsonExporter.create configuration_name: "#{args[:configuration_name]}_journeys", filepath: "#{args[:output_dir]}/#{args[:configuration_name]}_journeys.json" exporter.configure do |config| config.collection = journeys end - SimpleInterfacesHelper.run_interface_controlling_interruption exporter, :export, args + exports_group.add_interface exporter, "Services", :export + + exports_group.run end end end diff --git a/lib/tasks/helpers/simple_interfaces.rb b/lib/tasks/helpers/simple_interfaces.rb index 5b593be43..61dd38399 100644 --- a/lib/tasks/helpers/simple_interfaces.rb +++ b/lib/tasks/helpers/simple_interfaces.rb @@ -1,28 +1,11 @@ module SimpleInterfacesHelper - def self.interface_output_to_csv interface, output_dir - FileUtils.mkdir_p output_dir - filepath = File.join output_dir, + "#{interface.configuration_name}_#{Time.now.strftime "%y%m%d%H%M"}_out.csv" - cols = %w(line kind event message error) - if interface.reload.journal.size > 0 && interface.journal.first["row"].present? - keys = interface.journal.first["row"].map(&:first) - CSV.open(filepath, "w") do |csv| - csv << cols + keys - interface.journal.each do |j| - csv << cols.map{|c| j[c]} + j["row"].map(&:last) - end - end - puts "Task Output written in #{filepath}" - end - end - def self.run_interface_controlling_interruption interface, method, args begin interface.send(method, verbose: true) rescue Interrupt + interface.write_output_to_csv raise ensure - puts "\n\e[33m***\e[0m Done, status: " + (interface.status == "success" ? "\e[32m" : "\e[31m" ) + (interface.status || "") + "\e[0m" - interface_output_to_csv interface, args[:logs_output_dir] end end end diff --git a/lib/tasks/imports.rake b/lib/tasks/imports.rake index 7162f2ada..d393ab156 100644 --- a/lib/tasks/imports.rake +++ b/lib/tasks/imports.rake @@ -3,13 +3,13 @@ require 'tasks/helpers/simple_interfaces' namespace :import do desc "Notify parent imports when children finish" - task notify_parent: :environment do - ParentNotifier.new(Import).notify_when_finished + task notify_parent: :environment do + ParentNotifier.new(Import::Base).notify_when_finished end desc "Mark old unfinished Netex imports as 'aborted'" task netex_abort_old: :environment do - NetexImport.abort_old + Import::Netex.abort_old end desc "import the given file with the corresponding importer" |
