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();
}
Aggregations