gtfs 4.14.3 → 4.14.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -608,6 +608,7 @@ function setDefaultConfig(initialConfig) {
608
608
  const defaults = {
609
609
  sqlitePath: ":memory:",
610
610
  ignoreDuplicates: false,
611
+ ignoreErrors: false,
611
612
  gtfsRealtimeExpirationSeconds: 0
612
613
  };
613
614
  return {
@@ -633,7 +634,7 @@ var downloadGtfsRealtimeData = async (urlAndHeaders, task) => {
633
634
  });
634
635
  if (response.status !== 200) {
635
636
  task.logWarning(
636
- `Unable to download GTFS-Realtime from ${urlAndHeaders.url}`
637
+ `Unable to download GTFS-Realtime from ${urlAndHeaders.url}. Got status ${response.status}.`
637
638
  );
638
639
  return null;
639
640
  }
@@ -722,103 +723,127 @@ var updateRealtimeData = async (task) => {
722
723
  sqlitePath: task.sqlitePath
723
724
  });
724
725
  if (task.realtimeAlerts?.url) {
725
- const gtfsRealtimeData = await downloadGtfsRealtimeData(
726
- task.realtimeAlerts,
727
- task
728
- );
729
- if (gtfsRealtimeData?.entity) {
730
- task.log(`Download successful`);
731
- let totalLineCount = 0;
732
- for (const entity of gtfsRealtimeData.entity) {
733
- const fieldValues = serviceAlerts.schema.map(
734
- (column) => prepareRealtimeValue(entity, column, task)
735
- );
736
- try {
737
- db.prepare(
738
- `REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
739
- ).run();
740
- } catch (error) {
741
- task.logWarning("Import error: " + error.message);
742
- }
743
- const alertTargetArray = [];
744
- for (const informedEntity of entity.alert.informedEntity) {
745
- informedEntity.parent = entity;
746
- const subValues = serviceAlertTargets.schema.map(
747
- (column) => prepareRealtimeValue(informedEntity, column, task)
726
+ try {
727
+ const gtfsRealtimeData = await downloadGtfsRealtimeData(
728
+ task.realtimeAlerts,
729
+ task
730
+ );
731
+ if (gtfsRealtimeData?.entity) {
732
+ task.log(`Download successful`);
733
+ let totalLineCount = 0;
734
+ for (const entity of gtfsRealtimeData.entity) {
735
+ const fieldValues = serviceAlerts.schema.map(
736
+ (column) => prepareRealtimeValue(entity, column, task)
748
737
  );
749
- alertTargetArray.push(`(${subValues.join(", ")})`);
750
- totalLineCount++;
751
- }
752
- try {
753
- db.prepare(
754
- `REPLACE INTO ${serviceAlertTargets.filenameBase} (${serviceAlertTargets.schema.map((column) => column.name).join(", ")}) VALUES ${alertTargetArray.join(", ")}`
755
- ).run();
756
- } catch (error) {
757
- task.logWarning("Import error: " + error.message);
738
+ try {
739
+ db.prepare(
740
+ `REPLACE INTO ${serviceAlerts.filenameBase} (${serviceAlerts.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
741
+ ).run();
742
+ } catch (error) {
743
+ task.logWarning("Import error: " + error.message);
744
+ }
745
+ const alertTargetArray = [];
746
+ for (const informedEntity of entity.alert.informedEntity) {
747
+ informedEntity.parent = entity;
748
+ const subValues = serviceAlertTargets.schema.map(
749
+ (column) => prepareRealtimeValue(informedEntity, column, task)
750
+ );
751
+ alertTargetArray.push(`(${subValues.join(", ")})`);
752
+ totalLineCount++;
753
+ }
754
+ try {
755
+ db.prepare(
756
+ `REPLACE INTO ${serviceAlertTargets.filenameBase} (${serviceAlertTargets.schema.map((column) => column.name).join(", ")}) VALUES ${alertTargetArray.join(", ")}`
757
+ ).run();
758
+ } catch (error) {
759
+ task.logWarning("Import error: " + error.message);
760
+ }
761
+ task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
758
762
  }
759
- task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
763
+ }
764
+ } catch (error) {
765
+ if (task.ignoreErrors) {
766
+ task.logError(error.message);
767
+ } else {
768
+ throw error;
760
769
  }
761
770
  }
762
771
  }
763
772
  if (task.realtimeTripUpdates?.url) {
764
- const gtfsRealtimeData = await downloadGtfsRealtimeData(
765
- task.realtimeTripUpdates,
766
- task
767
- );
768
- if (gtfsRealtimeData?.entity) {
769
- task.log(`Download successful`);
770
- let totalLineCount = 0;
771
- for (const entity of gtfsRealtimeData.entity) {
772
- const fieldValues = tripUpdates.schema.map(
773
- (column) => prepareRealtimeValue(entity, column, task)
774
- );
775
- try {
776
- db.prepare(
777
- `REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
778
- ).run();
779
- } catch (error) {
780
- task.logWarning("Import error: " + error.message);
781
- }
782
- const stopTimeUpdateArray = [];
783
- for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
784
- stopTimeUpdate.parent = entity;
785
- const subValues = stopTimeUpdates.schema.map(
786
- (column) => prepareRealtimeValue(stopTimeUpdate, column, task)
773
+ try {
774
+ const gtfsRealtimeData = await downloadGtfsRealtimeData(
775
+ task.realtimeTripUpdates,
776
+ task
777
+ );
778
+ if (gtfsRealtimeData?.entity) {
779
+ task.log(`Download successful`);
780
+ let totalLineCount = 0;
781
+ for (const entity of gtfsRealtimeData.entity) {
782
+ const fieldValues = tripUpdates.schema.map(
783
+ (column) => prepareRealtimeValue(entity, column, task)
787
784
  );
788
- stopTimeUpdateArray.push(`(${subValues.join(", ")})`);
789
- totalLineCount++;
790
- }
791
- try {
792
- db.prepare(
793
- `REPLACE INTO ${stopTimeUpdates.filenameBase} (${stopTimeUpdates.schema.map((column) => column.name).join(", ")}) VALUES ${stopTimeUpdateArray.join(", ")}`
794
- ).run();
795
- } catch (error) {
796
- task.logWarning("Import error: " + error.message);
785
+ try {
786
+ db.prepare(
787
+ `REPLACE INTO ${tripUpdates.filenameBase} (${tripUpdates.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
788
+ ).run();
789
+ } catch (error) {
790
+ task.logWarning("Import error: " + error.message);
791
+ }
792
+ const stopTimeUpdateArray = [];
793
+ for (const stopTimeUpdate of entity.tripUpdate.stopTimeUpdate) {
794
+ stopTimeUpdate.parent = entity;
795
+ const subValues = stopTimeUpdates.schema.map(
796
+ (column) => prepareRealtimeValue(stopTimeUpdate, column, task)
797
+ );
798
+ stopTimeUpdateArray.push(`(${subValues.join(", ")})`);
799
+ totalLineCount++;
800
+ }
801
+ try {
802
+ db.prepare(
803
+ `REPLACE INTO ${stopTimeUpdates.filenameBase} (${stopTimeUpdates.schema.map((column) => column.name).join(", ")}) VALUES ${stopTimeUpdateArray.join(", ")}`
804
+ ).run();
805
+ } catch (error) {
806
+ task.logWarning("Import error: " + error.message);
807
+ }
808
+ task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
797
809
  }
798
- task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
810
+ }
811
+ } catch (error) {
812
+ if (task.ignoreErrors) {
813
+ task.logError(error.message);
814
+ } else {
815
+ throw error;
799
816
  }
800
817
  }
801
818
  }
802
819
  if (task.realtimeVehiclePositions?.url) {
803
- const gtfsRealtimeData = await downloadGtfsRealtimeData(
804
- task.realtimeVehiclePositions,
805
- task
806
- );
807
- if (gtfsRealtimeData?.entity) {
808
- task.log(`Download successful`);
809
- let totalLineCount = 0;
810
- for (const entity of gtfsRealtimeData.entity) {
811
- const fieldValues = vehiclePositions.schema.map(
812
- (column) => prepareRealtimeValue(entity, column, task)
813
- );
814
- try {
815
- db.prepare(
816
- `REPLACE INTO ${vehiclePositions.filenameBase} (${vehiclePositions.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
817
- ).run();
818
- } catch (error) {
819
- task.logWarning("Import error: " + error.message);
820
+ try {
821
+ const gtfsRealtimeData = await downloadGtfsRealtimeData(
822
+ task.realtimeVehiclePositions,
823
+ task
824
+ );
825
+ if (gtfsRealtimeData?.entity) {
826
+ task.log(`Download successful`);
827
+ let totalLineCount = 0;
828
+ for (const entity of gtfsRealtimeData.entity) {
829
+ const fieldValues = vehiclePositions.schema.map(
830
+ (column) => prepareRealtimeValue(entity, column, task)
831
+ );
832
+ try {
833
+ db.prepare(
834
+ `REPLACE INTO ${vehiclePositions.filenameBase} (${vehiclePositions.schema.map((column) => column.name).join(", ")}) VALUES (${fieldValues.join(", ")})`
835
+ ).run();
836
+ } catch (error) {
837
+ task.logWarning("Import error: " + error.message);
838
+ }
839
+ task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
820
840
  }
821
- task.log(`Importing - ${totalLineCount++} entries imported\r`, true);
841
+ }
842
+ } catch (error) {
843
+ if (task.ignoreErrors) {
844
+ task.logError(error.message);
845
+ } else {
846
+ throw error;
822
847
  }
823
848
  }
824
849
  }
@@ -841,31 +866,30 @@ async function updateGtfsRealtime(initialConfig) {
841
866
  )} using SQLite database at ${config.sqlitePath}`
842
867
  );
843
868
  deleteExpiredRealtimeData(config);
844
- await Promise.all(
845
- config.agencies.map(async (agency2) => {
846
- try {
847
- const task = {
848
- realtimeAlerts: agency2.realtimeAlerts,
849
- realtimeTripUpdates: agency2.realtimeTripUpdates,
850
- realtimeVehiclePositions: agency2.realtimeVehiclePositions,
851
- downloadTimeout: config.downloadTimeout,
852
- gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
853
- sqlitePath: config.sqlitePath,
854
- currentTimestamp: Math.floor(Date.now() / 1e3),
855
- log: log2,
856
- logWarning: logWarning2,
857
- logError: logError2
858
- };
859
- await updateRealtimeData(task);
860
- } catch (error) {
861
- if (config.ignoreErrors) {
862
- logError2(error.message);
863
- } else {
864
- throw error;
865
- }
869
+ await mapSeries(config.agencies, async (agency2) => {
870
+ try {
871
+ const task = {
872
+ realtimeAlerts: agency2.realtimeAlerts,
873
+ realtimeTripUpdates: agency2.realtimeTripUpdates,
874
+ realtimeVehiclePositions: agency2.realtimeVehiclePositions,
875
+ downloadTimeout: config.downloadTimeout,
876
+ gtfsRealtimeExpirationSeconds: config.gtfsRealtimeExpirationSeconds,
877
+ ignoreErrors: config.ignoreErrors,
878
+ sqlitePath: config.sqlitePath,
879
+ currentTimestamp: Math.floor(Date.now() / 1e3),
880
+ log: log2,
881
+ logWarning: logWarning2,
882
+ logError: logError2
883
+ };
884
+ await updateRealtimeData(task);
885
+ } catch (error) {
886
+ if (config.ignoreErrors) {
887
+ logError2(error.message);
888
+ } else {
889
+ throw error;
866
890
  }
867
- })
868
- );
891
+ }
892
+ });
869
893
  log2(
870
894
  `Completed GTFS-Realtime refresh for ${pluralize(
871
895
  "agencies",