Search in sources :

Example 1 with BatchProcessState

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;
}
Also used : BatchProcessState(com.pratilipi.common.type.BatchProcessState) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) DataAccessor(com.pratilipi.data.DataAccessor) BatchProcess(com.pratilipi.data.type.BatchProcess) Date(java.util.Date)

Aggregations

UnexpectedServerException (com.pratilipi.common.exception.UnexpectedServerException)1 BatchProcessState (com.pratilipi.common.type.BatchProcessState)1 DataAccessor (com.pratilipi.data.DataAccessor)1 BatchProcess (com.pratilipi.data.type.BatchProcess)1 Date (java.util.Date)1