Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,22 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
metadataRepository.updateProgress(jobId, 2, 3, "Scheduling cleanup job");

if (promote > 0) {
this.userNotificationService.newLocationData(user, data.device, timeRange);
this.jobSchedulingService.enqueueTask(locationDataCleanupTask,
new LocationDataCleanupTask.TaskData(user, data.getDevice(), timeRange.start(), timeRange.end()).withParentJobId(data.getParentJobId()),
JobSchedulingService.Metadata.builder()
.user(user)
.jobType(JobType.LOCATION_DATA_CLEANUP)
.friendlyName("Location Data Cleanup")
.build());
if (timeRange.equals(TimeRange.empty())) {
log.debug("No timerange found for partitionKey [{}], recalculating", partitionKey);
timeRange = this.stagingService.getWholeTimeRange(partitionKey);
}
if (timeRange.equals(TimeRange.empty())) {
log.warn("Still no timerange found for partitionKey [{}], skipping cleanup", partitionKey);
} else {
this.userNotificationService.newLocationData(user, data.device, timeRange);
this.jobSchedulingService.enqueueTask(locationDataCleanupTask,
new LocationDataCleanupTask.TaskData(user, data.getDevice(), timeRange.start(), timeRange.end()).withParentJobId(data.getParentJobId()),
JobSchedulingService.Metadata.builder()
.user(user)
.jobType(JobType.LOCATION_DATA_CLEANUP)
.friendlyName("Location Data Cleanup")
.build());
}
} else {
log.debug("No points to promote, timerange was [{}]", timeRange);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,28 @@ ON CONFLICT (user_id, device_id, timestamp) DO NOTHING
return insertedIds.size();
}

public TimeRange getWholeTimeRange(String partitionKey) {
String sql = "SELECT MIN(timestamp) as start_time, MAX(timestamp) as end_time FROM staging_location_points WHERE partition_key = ?";
return this.jdbcTemplate.queryForObject(sql, (rs, rowNum) -> {
Timestamp start = rs.getTimestamp("start_time");
Timestamp end = rs.getTimestamp("end_time");

if (start == null || end == null) {
return TimeRange.empty();
}

return new TimeRange(start.toInstant(), end.toInstant());
}, partitionKey);
}

public TimeRange getTimeRange(String partitionKey) {
String sql = "SELECT MIN(timestamp) as start_time, MAX(timestamp) as end_time FROM staging_location_points WHERE partition_key = ? AND promoted = FALSE";
return this.jdbcTemplate.queryForObject(sql, (rs, rowNum) -> {
Timestamp start = rs.getTimestamp("start_time");
Timestamp end = rs.getTimestamp("end_time");

if (start == null || end == null) {
return null;
return TimeRange.empty();
}

return new TimeRange(start.toInstant(), end.toInstant());
Expand Down
Loading