Skip to content

Commit f9b5032

Browse files
committed
fix(feed-fetch): fix NPEs encountered during feed fetch operations.
fixes #127
1 parent 3e47cec commit f9b5032

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public FetchProjectFeedsJob (Project project, String owner) {
3030
@Override
3131
public void jobLogic() {
3232
Project project = Persistence.projects.getById(projectId);
33+
if (project == null) {
34+
LOG.error("Fetch feeds job failed because project {} does not exist in database. Clearing the project's scheduled fetch jobs.");
35+
DataManager.autoFetchMap.remove(projectId);
36+
return;
37+
}
3338
LOG.info("Fetch job running for {} project at {}", project.name, ZonedDateTime.now(ZoneId.of("America/New_York")));
3439
Collection<FeedSource> projectFeeds = project.retrieveProjectFeedSources();
3540
for(FeedSource feedSource : projectFeeds) {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public FetchSingleFeedJob (FeedSource feedSource, String owner, boolean continue
3434
*/
3535
@JsonProperty
3636
public String getFeedVersionId () {
37-
return result.id;
37+
// Feed version result is null unless (and until) fetch is successful.
38+
return result != null ? result.id : null;
3839
}
3940

4041
@JsonProperty
4142
public String getFeedSourceId () {
42-
return result.parentFeedSource().id;
43+
// Feed version result is null unless (and until) fetch is successful.
44+
return result != null ? result.parentFeedSource().id : null;
4345
}
4446

4547
@Override

src/main/java/com/conveyal/datatools/manager/models/FeedSource.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ public FeedVersion fetch (MonitorableJob.Status status) {
151151
public FeedVersion fetch (MonitorableJob.Status status, String optionalUrlOverride) {
152152
status.message = "Downloading file";
153153

154-
FeedVersion latest = retrieveLatest();
155-
156154
// We create a new FeedVersion now, so that the fetched date is (milliseconds) before
157155
// fetch occurs. That way, in the highly unlikely event that a feed is updated while we're
158156
// fetching it, we will not miss a new feed.
@@ -189,7 +187,8 @@ public FeedVersion fetch (MonitorableJob.Status status, String optionalUrlOverri
189187
}
190188

191189
conn.setDefaultUseCaches(true);
192-
190+
// Get latest version to check that the fetched version does not duplicate a feed already loaded.
191+
FeedVersion latest = retrieveLatest();
193192
// lastFetched is set to null when the URL changes and when latest feed version is deleted
194193
if (latest != null && this.lastFetched != null)
195194
conn.setIfModifiedSince(Math.min(latest.updated.getTime(), this.lastFetched.getTime()));

0 commit comments

Comments
 (0)