Skip to content

Commit 7bbd091

Browse files
committed
logging scheduled tasks process time
1 parent 11aa32b commit 7bbd091

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

telegram-bot/src/main/java/project/vilsoncake/telegrambot/bot/ScheduleSender.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,16 @@ public class ScheduleSender {
5353
private final AircraftUtils aircraftUtils;
5454
private final List<Map<String, List<String>>> aircraftFamiliesCodes;
5555
private final UnitsUtils unitsUtils;
56+
private final LoggingUtils loggingUtils;
5657
private final WebClient apiWebClient;
5758
private final BotSender botSender;
5859

5960
@Transactional
6061
@Scheduled(fixedDelay = SCHEDULED_FLIGHTS_CHECK_DELAY_IN_MINUTES, timeUnit = TimeUnit.MINUTES)
6162
public void sendNewScheduledAndLiveWideBodyFlights() throws InterruptedException {
62-
log.info("Schedule sending wide body flights started...");
63+
log.info("Schedule sending wide-body flights started...");
64+
65+
long startTime = System.currentTimeMillis();
6366

6467
List<String> uniqueAirports = userService.findUniqueAirports();
6568
Map<String, FlightsDto> uniqueAirportsFlights = new HashMap<>();
@@ -165,14 +168,19 @@ public void sendNewScheduledAndLiveWideBodyFlights() throws InterruptedException
165168
}
166169
}
167170
}
168-
log.info("Schedule sending wide body flights finished.");
171+
172+
long endTime = System.currentTimeMillis();
173+
174+
log.info("Schedule sending wide-body flights finished. {}", loggingUtils.getFinishedProcessTime(startTime, endTime));
169175
}
170176

171177
@Transactional
172178
@Scheduled(fixedDelay = LANDING_FLIGHTS_CHECK_DELAY_IN_MINUTES, timeUnit = TimeUnit.MINUTES)
173179
public void sendLandingWideBodyFlights() throws InterruptedException {
174180
log.info("Schedule sending landing flights started...");
175181

182+
long startTime = System.currentTimeMillis();
183+
176184
List<FlightEntity> uniqueRegistrations = flightService.findUniqueFlightsRegistrations();
177185
List<FlightDataDto> flightDataDtos = new ArrayList<>();
178186

@@ -251,12 +259,18 @@ public void sendLandingWideBodyFlights() throws InterruptedException {
251259
}
252260
}
253261
}
254-
log.info("Schedule sending landing flights finished.");
262+
263+
long endTime = System.currentTimeMillis();
264+
265+
log.info("Schedule sending landing flights finished. {}", loggingUtils.getFinishedProcessTime(startTime, endTime));
255266
}
256267

257268
@Scheduled(fixedDelay = AN_124_FLIGHTS_CHECK_DELAY_IN_MINUTES, timeUnit = TimeUnit.MINUTES)
258269
public void sendNewAn124Flights() {
259270
log.info("Schedule sending An-124 flights started...");
271+
272+
long startTime = System.currentTimeMillis();
273+
260274
List<UserEntity> users = userService.findAllUsers();
261275

262276
An124FlightsDto an124FlightsDto;
@@ -588,6 +602,9 @@ public void sendNewAn124Flights() {
588602
}
589603
}
590604
}
591-
log.info("Schedule sending An-124 flights finished.");
605+
606+
long endTime = System.currentTimeMillis();
607+
608+
log.info("Schedule sending An-124 flights finished. {}", loggingUtils.getFinishedProcessTime(startTime, endTime));
592609
}
593610
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package project.vilsoncake.telegrambot.utils;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
@Component
6+
public class LoggingUtils {
7+
8+
public String getFinishedProcessTime(long startTime, long endTime) {
9+
double timeInSeconds = (double) (endTime - startTime) / 1000;
10+
11+
if (timeInSeconds < 60) {
12+
return String.format("Process time: %s seconds.", timeInSeconds);
13+
}
14+
15+
int timeInMinutes = (int) (timeInSeconds / 60);
16+
int remainder = (int) (timeInSeconds % 60);
17+
18+
return String.format("Process time: %s minutes %s seconds.", timeInMinutes, remainder);
19+
}
20+
}

0 commit comments

Comments
 (0)