Properly requeue on exception
This commit is contained in:
parent
6d319cd378
commit
05d4c2ded6
@ -85,14 +85,20 @@ public class TripService implements ITripService {
|
|||||||
public void match(Long tripId, MatchDTO match) throws EntityNotFoundException, DriverNotAvailableException, IllegalStateException {
|
public void match(Long tripId, MatchDTO match) throws EntityNotFoundException, DriverNotAvailableException, IllegalStateException {
|
||||||
ITrip trip;
|
ITrip trip;
|
||||||
IMatch newMatch;
|
IMatch newMatch;
|
||||||
|
IDriver driver;
|
||||||
try {
|
try {
|
||||||
trip = getTrip(tripId);
|
trip = getTrip(tripId);
|
||||||
IDriver driver = getDriver(match.getDriverId());
|
driver = getDriver(match.getDriverId());
|
||||||
IMatchDAO matchDAO = daoFactory.createMatchDAO();
|
List<IMatch> matches = daoFactory.createMatchDAO().findAll();
|
||||||
for (IMatch m : matchDAO.findAll()) {
|
for (IMatch existingMatch : matches) {
|
||||||
if (m.getDriver() != null && m.getDriver().getId().equals(driver.getId()))
|
if (existingMatch.getDriver().getId().equals(match.getDriverId())) {
|
||||||
throw new DriverNotAvailableException("Driver with id " + driver.getId() + " is already busy");
|
throw new DriverNotAvailableException("Driver with id " + driver.getId() + " is already busy");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
matchingService.queueTripForMatching(tripId);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
IVehicle vehicle = getVehicle(match.getVehicleId());
|
IVehicle vehicle = getVehicle(match.getVehicleId());
|
||||||
|
|
||||||
@ -109,11 +115,6 @@ public class TripService implements ITripService {
|
|||||||
|
|
||||||
trip.setMatch(newMatch);
|
trip.setMatch(newMatch);
|
||||||
trip.setState(TripState.MATCHED);
|
trip.setState(TripState.MATCHED);
|
||||||
} catch (Exception e) {
|
|
||||||
// Requeue match
|
|
||||||
matchingService.queueTripForMatching(tripId);
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
entityManager.merge(trip);
|
entityManager.merge(trip);
|
||||||
entityManager.persist(newMatch);
|
entityManager.persist(newMatch);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user