From 24ede57980f444558e7b76f941181354e0bd542c Mon Sep 17 00:00:00 2001 From: Stephen Yeargin Date: Sat, 16 Mar 2024 09:30:39 -0500 Subject: [PATCH] Handle stray dates --- lib/tasks/import.rake | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 1f4567d..24a380b 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -78,10 +78,14 @@ namespace :import do puts 'calendar_dates.txt' begin @source = GTFS::Source.build ENV.fetch('GTFS_URL', nil) - CalendarDate.bulk_insert do |worker| - @source.each_calendar_date do |row| - worker.add(CalendarDate.hash_from_gtfs(row)) + @source.each_calendar_date do |row| + date = CalendarDate.new(CalendarDate.hash_from_gtfs(row)) + if date.calendar_id.nil? + puts "[ERROR] Calendar ID is nil for #{date.service_id} / #{date.date}" + next end + + date.save end rescue Errno::ENOENT puts '[warning] File does not exist.'