Skip to content

Commit 3f80a65

Browse files
fix(AutoPublishJob): Prevent publishing if errors were found.
1 parent 8c9ad6b commit 3f80a65

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/main/java/com/conveyal/datatools/manager/jobs/AutoPublishJob.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ protected void innerJobLogic() throws Exception {
4343
// Validate and check for blocking issues in the feed version to deploy.
4444
if (latestFeedVersion.hasBlockingIssuesForPublishing()) {
4545
status.fail("Could not publish this feed version because it contains blocking errors.");
46-
}
47-
48-
try {
49-
GtfsPlusValidation gtfsPlusValidation = GtfsPlusValidation.validate(latestFeedVersion.id);
50-
if (!gtfsPlusValidation.issues.isEmpty()) {
51-
status.fail("Could not publish this feed version because it contains GTFS+ blocking errors.");
46+
} else {
47+
try {
48+
GtfsPlusValidation gtfsPlusValidation = GtfsPlusValidation.validate(latestFeedVersion.id);
49+
if (!gtfsPlusValidation.issues.isEmpty()) {
50+
status.fail("Could not publish this feed version because it contains GTFS+ blocking errors.");
51+
}
52+
} catch(Exception e) {
53+
status.fail("Could not read GTFS+ zip file", e);
5254
}
53-
} catch(Exception e) {
54-
status.fail("Could not read GTFS+ zip file", e);
5555
}
5656

5757
// If validation successful, just execute the feed updating process.
58-
FeedVersionController.publishToExternalResource(latestFeedVersion);
59-
LOG.info("Auto-published feed source {} to external resource.", feedSource.id);
58+
if (!status.error) {
59+
FeedVersionController.publishToExternalResource(latestFeedVersion);
60+
LOG.info("Auto-published feed source {} to external resource.", feedSource.id);
61+
}
6062
}
6163
}

src/test/java/com/conveyal/datatools/manager/jobs/AutoPublishJobTest.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@ public static void tearDown() {
8888
@MethodSource("createPublishFeedCases")
8989
void shouldProcessFeed(String resourceName, boolean isError, String errorMessage) throws IOException {
9090
// Add the version to the feed source
91+
FeedVersion originalFeedVersion;
9192
if (resourceName.endsWith(".zip")) {
92-
createFeedVersionFromGtfsZip(feedSource, resourceName);
93+
originalFeedVersion = createFeedVersionFromGtfsZip(feedSource, resourceName);
9394
} else {
94-
createFeedVersion(feedSource, zipFolderFiles(resourceName));
95+
originalFeedVersion = createFeedVersion(feedSource, zipFolderFiles(resourceName));
9596
}
9697

9798
// Create the job
@@ -108,6 +109,10 @@ void shouldProcessFeed(String resourceName, boolean isError, String errorMessage
108109

109110
if (isError) {
110111
assertEquals(errorMessage, autoPublishJob.status.message);
112+
113+
// In case of error, the sentToExternalPublisher flag should not be set.
114+
FeedVersion updatedFeedVersion = Persistence.feedVersions.getById(originalFeedVersion.id);
115+
assertNull(updatedFeedVersion.sentToExternalPublisher);
111116
}
112117
}
113118

0 commit comments

Comments
 (0)