use of com.pratilipi.common.type.BatchProcessState in project pratilipi by Pratilipi.
the class BatchProcessDataUtil method exec.
public static boolean exec(Long batchProcessId) throws UnexpectedServerException {
DataAccessor dataAccessor = DataAccessorFactory.getDataAccessor();
BatchProcess batchProcess = dataAccessor.getBatchProcess(batchProcessId);
if (batchProcess.getStartAt().after(new Date()))
return false;
if (batchProcess.getStateInProgress() != null && !batchProcess.getStateInProgress().isTimedOut(batchProcess.getLastUpdated()))
return false;
BatchProcessState currState = batchProcess.getType().getNextState(batchProcess.getStateCompleted());
if (currState == null)
throw new UnexpectedServerException();
batchProcess.setStateInProgress(currState);
batchProcess.setLastUpdated(new Date());
batchProcess = dataAccessor.createOrUpdateBatchProcess(batchProcess);
System.out.println("Process Id: " + batchProcess.getId());
System.out.println("Process Type: " + batchProcess.getType());
System.out.println("Process State: " + batchProcess.getStateInProgress());
if (currState == BatchProcessState.INIT)
_execStateInit(batchProcess);
else if (currState == BatchProcessState.GET_USER_IDS_BY_AUTHOR_FILTER)
_execStateGetUserIdsByAuthorFilter(batchProcess);
else if (currState == BatchProcessState.CREATE_NOTIFICATIONS_FOR_USER_IDS)
_execStateCreateNotificationsForUserIds(batchProcess);
else if (currState == BatchProcessState.VALIDATE_NOTIFICATION_COUNT)
_execStateValidateNotificationCount(batchProcess);
else if (currState == BatchProcessState.COMPLETED)
batchProcess.setStateCompleted(currState);
batchProcess.setStateInProgress(null);
batchProcess.setLastUpdated(new Date());
// Saving Entity
batchProcess = dataAccessor.createOrUpdateBatchProcess(batchProcess);
return true;
}
Aggregations