@Test public void testCalculateRuntimeLimitForJustStartedJob() { Instant now = Instant.now(); Instant startedAt = now; assertEquals(10, JobHelper.calculateRuntimeDuration(10, startedAt)); }
public static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt) { long terminateJobInSecs = maxRuntimeSecs; if (maxRuntimeSecs > 0) { Instant now = Instant.now(); if (now.isAfter(startedAt)) { long elapsedSeconds = now.getEpochSecond() - startedAt.getEpochSecond(); terminateJobInSecs = maxRuntimeSecs - elapsedSeconds; if (terminateJobInSecs <= 0) { terminateJobInSecs = 1; } } } return terminateJobInSecs; }
JobHelper { public static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt) { long terminateJobInSecs = maxRuntimeSecs; if (maxRuntimeSecs > 0) { Instant now = Instant.now(); if (now.isAfter(startedAt)) { long elapsedSeconds = now.getEpochSecond() - startedAt.getEpochSecond(); terminateJobInSecs = maxRuntimeSecs - elapsedSeconds; if (terminateJobInSecs <= 0) { terminateJobInSecs = 1; } } } return terminateJobInSecs; } }
JobHelper { public static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt) { long terminateJobInSecs = maxRuntimeSecs; if (maxRuntimeSecs > 0) { Instant now = Instant.now(); if (now.isAfter(startedAt)) { long elapsedSeconds = now.getEpochSecond() - startedAt.getEpochSecond(); terminateJobInSecs = maxRuntimeSecs - elapsedSeconds; if (terminateJobInSecs <= 0) { terminateJobInSecs = 1; } } } return terminateJobInSecs; } private  JobHelper(); }
JobHelper { public static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt) { long terminateJobInSecs = maxRuntimeSecs; if (maxRuntimeSecs > 0) { Instant now = Instant.now(); if (now.isAfter(startedAt)) { long elapsedSeconds = now.getEpochSecond() - startedAt.getEpochSecond(); terminateJobInSecs = maxRuntimeSecs - elapsedSeconds; if (terminateJobInSecs <= 0) { terminateJobInSecs = 1; } } } return terminateJobInSecs; } private  JobHelper(); static List<Integer> getUserStageNumbers(SchedulingInfo schedulingInfo, boolean hasJobMaster); static boolean isTerminalWorkerEvent(WorkerEvent workerEvent); static Optional<String> getWorkerHostFromWorkerEvent(WorkerEvent event); static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt); }
JobHelper { public static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt) { long terminateJobInSecs = maxRuntimeSecs; if (maxRuntimeSecs > 0) { Instant now = Instant.now(); if (now.isAfter(startedAt)) { long elapsedSeconds = now.getEpochSecond() - startedAt.getEpochSecond(); terminateJobInSecs = maxRuntimeSecs - elapsedSeconds; if (terminateJobInSecs <= 0) { terminateJobInSecs = 1; } } } return terminateJobInSecs; } private  JobHelper(); static List<Integer> getUserStageNumbers(SchedulingInfo schedulingInfo, boolean hasJobMaster); static boolean isTerminalWorkerEvent(WorkerEvent workerEvent); static Optional<String> getWorkerHostFromWorkerEvent(WorkerEvent event); static long calculateRuntimeDuration(long maxRuntimeSecs, Instant startedAt);  }