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 {
|
||||
ITrip trip;
|
||||
IMatch newMatch;
|
||||
IDriver driver;
|
||||
try {
|
||||
trip = getTrip(tripId);
|
||||
IDriver driver = getDriver(match.getDriverId());
|
||||
IMatchDAO matchDAO = daoFactory.createMatchDAO();
|
||||
for (IMatch m : matchDAO.findAll()) {
|
||||
if (m.getDriver() != null && m.getDriver().getId().equals(driver.getId()))
|
||||
driver = getDriver(match.getDriverId());
|
||||
List<IMatch> matches = daoFactory.createMatchDAO().findAll();
|
||||
for (IMatch existingMatch : matches) {
|
||||
if (existingMatch.getDriver().getId().equals(match.getDriverId())) {
|
||||
throw new DriverNotAvailableException("Driver with id " + driver.getId() + " is already busy");
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
matchingService.queueTripForMatching(tripId);
|
||||
throw e;
|
||||
}
|
||||
|
||||
IVehicle vehicle = getVehicle(match.getVehicleId());
|
||||
|
||||
@ -109,11 +115,6 @@ public class TripService implements ITripService {
|
||||
|
||||
trip.setMatch(newMatch);
|
||||
trip.setState(TripState.MATCHED);
|
||||
} catch (Exception e) {
|
||||
// Requeue match
|
||||
matchingService.queueTripForMatching(tripId);
|
||||
throw e;
|
||||
}
|
||||
|
||||
entityManager.merge(trip);
|
||||
entityManager.persist(newMatch);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user