diff --git a/src/main/java/com/conveyal/datatools/common/status/MonitorableJob.java b/src/main/java/com/conveyal/datatools/common/status/MonitorableJob.java index b5c9654ee..8b1bbee6c 100644 --- a/src/main/java/com/conveyal/datatools/common/status/MonitorableJob.java +++ b/src/main/java/com/conveyal/datatools/common/status/MonitorableJob.java @@ -176,12 +176,13 @@ public void run () { // because the error presumably already occurred and has a better error message. cancel(cancelMessage); } - // Run final steps of job pending completion or error. Note: any tasks that depend on job success should - // check job status to determine if final step should be executed (e.g., storing feed version in MongoDB). - // TODO: should we add separate hooks depending on state of job/sub-tasks (e.g., success, catch, finally) // Complete the job (as success if no errors encountered, as failure otherwise). if (!parentJobErrored && !subTaskErrored) status.completeSuccessfully("Job complete!"); else status.complete(true); + // Run final steps of job pending completion or error. Note: any tasks that depend on job success should + // check job status in jobFinished to determine if final step should be executed (e.g., storing feed + // version in MongoDB). + // TODO: should we add separate hooks depending on state of job/sub-tasks (e.g., success, catch, finally) jobFinished(); // We retain finished or errored jobs on the server until they are fetched via the API, which implies they diff --git a/src/main/java/com/conveyal/datatools/editor/jobs/CreateSnapshotJob.java b/src/main/java/com/conveyal/datatools/editor/jobs/CreateSnapshotJob.java index 317d872f1..04fe9ae9e 100644 --- a/src/main/java/com/conveyal/datatools/editor/jobs/CreateSnapshotJob.java +++ b/src/main/java/com/conveyal/datatools/editor/jobs/CreateSnapshotJob.java @@ -87,7 +87,7 @@ public void jobLogic() { Collection existingSnapshots = feedSource.retrieveSnapshots(); int version = existingSnapshots.size(); status.update("Creating snapshot...", 20); - FeedLoadResult loadResult = makeSnapshot(namespace, DataManager.GTFS_DATA_SOURCE); + FeedLoadResult loadResult = makeSnapshot(namespace, DataManager.GTFS_DATA_SOURCE, !feedSource.preserveStopTimesSequence); snapshot.version = version; snapshot.namespace = loadResult.uniqueIdentifier; snapshot.feedLoadResult = loadResult; diff --git a/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java b/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java index 345bc234c..95d2de8d2 100644 --- a/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java +++ b/src/main/java/com/conveyal/datatools/editor/jobs/ExportSnapshotToGTFSJob.java @@ -21,6 +21,7 @@ public class ExportSnapshotToGTFSJob extends MonitorableJob { private static final Logger LOG = LoggerFactory.getLogger(ExportSnapshotToGTFSJob.class); private final Snapshot snapshot; private final String feedVersionId; + private File tempFile; public ExportSnapshotToGTFSJob(Auth0UserProfile owner, Snapshot snapshot, String feedVersionId) { super(owner, "Exporting snapshot " + snapshot.name, JobType.EXPORT_SNAPSHOT_TO_GTFS); @@ -40,7 +41,6 @@ public Snapshot getSnapshot () { @Override public void jobLogic() { - File tempFile; try { tempFile = File.createTempFile("snapshot", "zip"); } catch (IOException e) { @@ -52,6 +52,7 @@ public void jobLogic() { FeedLoadResult result = exporter.exportTables(); if (result.fatalException != null) { status.fail(String.format("Error (%s) encountered while exporting database tables.", result.fatalException)); + return; } // Override snapshot ID if exporting feed for use as new feed version. @@ -71,12 +72,15 @@ public void jobLogic() { status.fail(String.format("Could not store feed for snapshot %s", snapshot.id), e); } } - // Delete snapshot temp file. - tempFile.delete(); } @Override public void jobFinished () { if (!status.error) status.completeSuccessfully("Export complete!"); + // Delete snapshot temp file. + if (tempFile != null) { + LOG.info("Deleting temporary GTFS file for exported snapshot at {}", tempFile.getAbsolutePath()); + tempFile.delete(); + } } } diff --git a/src/main/java/com/conveyal/datatools/manager/models/FeedSource.java b/src/main/java/com/conveyal/datatools/manager/models/FeedSource.java index 27fc41cee..a305f9584 100644 --- a/src/main/java/com/conveyal/datatools/manager/models/FeedSource.java +++ b/src/main/java/com/conveyal/datatools/manager/models/FeedSource.java @@ -47,9 +47,18 @@ public class FeedSource extends Model implements Cloneable { /** * The collection of which this feed is a part */ - //@JsonView(JsonViews.DataDump.class) public String projectId; + /** + * When snapshotting a GTFS feed for editing, gtfs-lib currently defaults to normalize stop sequence values to be + * zero-based and incrementing. This can muck with GTFS files that are linked to GTFS-rt feeds by stop_sequence, so + * this override flag currently provides a workaround for feeds that need to be edited but do not need to edit + * stop_times or individual patterns. WARNING: enabling this flag for a feed and then attempting to edit patterns in + * complicated ways (e.g., modifying the order of pattern stops) could have unexpected consequences. There is no UI + * setting for this and it is not recommended to do this unless absolutely necessary. + */ + public boolean preserveStopTimesSequence; + /** * Get the Project of which this feed is a part */