Skip to content

Commit

Permalink
OTP-1465 Implement start time for trip history upload.
Browse files Browse the repository at this point in the history
  • Loading branch information
JymDyerIBI committed Nov 22, 2024
1 parent ab2a094 commit caa9f2d
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
import java.io.File;
import java.io.IOException;
import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
Expand Down Expand Up @@ -63,6 +65,9 @@ public class ConnectedDataManager {
private static final int CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_JOB_FREQUENCY_IN_MINUTES =
getConfigPropertyAsInt("CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_JOB_FREQUENCY_IN_MINUTES", 5);

private static final String CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_START_TIME =
getConfigPropertyAsText("CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_START_TIME", "03:00");

private static final Logger LOG = LoggerFactory.getLogger(ConnectedDataManager.class);

public static final String CONNECTED_DATA_PLATFORM_S3_BUCKET_NAME =
Expand Down Expand Up @@ -110,11 +115,18 @@ public static boolean canScheduleUploads() {

public static void scheduleTripHistoryUploadJob() {
if (canScheduleUploads()) {
LOG.info("Scheduling trip history upload for every {} minute(s)",
CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_JOB_FREQUENCY_IN_MINUTES);
LOG.info("Scheduling trip history upload for every {} minute(s) starting at {}",
CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_JOB_FREQUENCY_IN_MINUTES,
CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_START_TIME);

var now = DateTimeUtils.nowAsZonedDateTime(DateTimeUtils.getOtpZoneId());
var timeOfDay = LocalTime.parse(CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_START_TIME);
var startAt = DateTimeUtils.getNextTimeFrom(timeOfDay, now);
long initialDelayMinutes = Duration.between(now, startAt).toMinutes();

Scheduler.scheduleJob(
new TripHistoryUploadJob(),
0,
initialDelayMinutes,
CONNECTED_DATA_PLATFORM_TRIP_HISTORY_UPLOAD_JOB_FREQUENCY_IN_MINUTES,
TimeUnit.MINUTES);
}
Expand Down

0 comments on commit caa9f2d

Please sign in to comment.