Search in sources :

Example 1 with IdmDependentTaskTrigger

use of eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger in project CzechIdMng by bcvsolutions.

the class LongRunningTaskExecuteDependentProcessor method process.

@Override
public EventResult<IdmLongRunningTaskDto> process(EntityEvent<IdmLongRunningTaskDto> event) {
    IdmLongRunningTaskDto longRunningTask = event.getContent();
    IdmScheduledTaskDto scheduledTask = service.findByLongRunningTaskId(longRunningTask.getId());
    if (scheduledTask == null) {
        LOG.debug("Ecexute dependent tasks is supported for scheduled tasks. LRT [{}] does not have scheduled task.", longRunningTask.getId());
        return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
    }
    List<IdmDependentTaskTrigger> dependentTasks = dependentTaskTriggerRepository.findByInitiatorTaskId(scheduledTask.getQuartzTaskName());
    if (dependentTasks.isEmpty()) {
        LOG.trace("Task [{}] has not dependent tasks.", longRunningTask.getId());
        return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
    }
    // 
    if (longRunningTask.getResultState() != OperationState.EXECUTED) {
        LOG.debug("Task [{}] was not successfully executed. Dependent tasks [{}] will not be executed.", longRunningTask.getId(), dependentTasks.size());
        return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.NOT_EXECUTED)).build();
    }
    // find all triggers by quartz task name = job detail name. Default group is supported now only
    dependentTaskTriggerRepository.findByInitiatorTaskId(scheduledTask.getQuartzTaskName()).forEach(dependentTaskTrigger -> {
        LOG.info("Scheduled task [{}] ended. Dependent task [{}] will be executed in dryRun [{}].", dependentTaskTrigger.getInitiatorTaskId(), dependentTaskTrigger.getDependentTaskId(), longRunningTask.isDryRun());
        schedulerManager.runTask(dependentTaskTrigger.getDependentTaskId(), longRunningTask.isDryRun());
    });
    return new DefaultEventResult.Builder<IdmLongRunningTaskDto>(event, this).setResult(new OperationResult(OperationState.EXECUTED)).build();
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) IdmDependentTaskTrigger(eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger) IdmScheduledTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto) OperationResult(eu.bcvsolutions.idm.core.api.entity.OperationResult)

Aggregations

OperationResult (eu.bcvsolutions.idm.core.api.entity.OperationResult)1 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)1 IdmScheduledTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmScheduledTaskDto)1 IdmDependentTaskTrigger (eu.bcvsolutions.idm.core.scheduler.entity.IdmDependentTaskTrigger)1