use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.
the class DefaultFileProcessingChain method getSettledSequencingObject.
/**
* Checks the {@link SequenceFile}s for the given {@link SequencingObject}
* to see if it's files are in the place they should be. Since there's lots
* of saves going on during the {@link FileProcessingChain} the transaction
* might not be complete in the time the file is first read.
*
* @param sequencingObjectId
* the id of the {@link SequencingObject} to check
* @return the settled {@link SequencingObject}
* @throws FileProcessorTimeoutException
* if the files don't settle in the configured timeout
*/
private SequencingObject getSettledSequencingObject(Long sequencingObjectId) throws FileProcessorTimeoutException {
boolean filesNotSettled = true;
Integer waiting = 0;
SequencingObject sequencingObject;
do {
if (waiting > timeout) {
throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out. File id " + sequencingObjectId);
}
waiting++;
try {
Thread.sleep(sleepDuration);
} catch (InterruptedException e) {
}
sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
Set<SequenceFile> files = sequencingObject.getFiles();
filesNotSettled = files.stream().anyMatch(f -> {
return !Files.exists(f.getFile());
});
} while (filesNotSettled);
return sequencingObject;
}
use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.
the class DefaultFileProcessingChain method launchChain.
/**
* {@inheritDoc}
*/
@Override
public List<Exception> launchChain(Long sequencingObjectId) throws FileProcessorTimeoutException {
List<Exception> ignoredExceptions = new ArrayList<>();
Integer waiting = 0;
// file has been persisted in the database.
while (!sequencingObjectRepository.exists(sequencingObjectId)) {
if (waiting > timeout) {
throw new FileProcessorTimeoutException("Waiting for longer than " + sleepDuration * timeout + "ms, bailing out.");
}
waiting++;
try {
Thread.sleep(sleepDuration);
} catch (InterruptedException e) {
}
}
for (FileProcessor fileProcessor : fileProcessors) {
try {
if (fileProcessor.shouldProcessFile(sequencingObjectId)) {
SequencingObject settledSequencingObject = getSettledSequencingObject(sequencingObjectId);
fileProcessor.process(settledSequencingObject);
}
} catch (FileProcessorException e) {
SequencingObject sequencingObject = sequencingObjectRepository.findOne(sequencingObjectId);
qcRepository.save(new FileProcessorErrorQCEntry(sequencingObject));
// execution (show the error, but proceed).
if (fileProcessor.modifiesFile() || fastFail) {
throw e;
} else {
ignoredExceptions.add(e);
logger.error("File processor [" + fileProcessor.getClass() + "] failed to process [" + sequencingObjectId + "], but proceeding with the remaining processors because the " + "file would not be modified by the processor. Stack trace follows.", e);
}
}
}
return ignoredExceptions;
}
use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.
the class SequenceFileProcessorLauncher method run.
@Override
public void run() {
// when running in single-threaded mode, the security context should
// already be populated in the current thread and and we shouldn't
// have to overwrite and erase the context before execution.
boolean copiedSecurityContext = true;
SecurityContext context = SecurityContextHolder.getContext();
if (context == null || context.getAuthentication() == null) {
SecurityContextHolder.setContext(securityContext);
} else {
copiedSecurityContext = false;
}
// proceed with analysis
try {
fileProcessingChain.launchChain(sequencingObjectId);
} catch (FileProcessorTimeoutException e) {
logger.error("FileProcessingChain did *not* execute -- the transaction opened by SequenceFileService never closed.", e);
}
// current thread.
if (copiedSecurityContext) {
SecurityContextHolder.clearContext();
}
}
use of ca.corefacility.bioinformatics.irida.exceptions.FileProcessorTimeoutException in project irida by phac-nml.
the class DefaultFileProcessingChainTest method testFailWithContinueChain.
@Test
public void testFailWithContinueChain() throws FileProcessorTimeoutException {
FileProcessingChain fileProcessingChain = new DefaultFileProcessingChain(objectRepository, qcRepository, new FailingFileProcessor());
when(objectRepository.exists(objectId)).thenReturn(true);
List<Exception> exceptions = fileProcessingChain.launchChain(1L);
// exceptions should be ignored in this test
assertEquals("exactly one exception should have been ignored.", 1, exceptions.size());
assertTrue("ignored exception should be of type FileProcessorException.", exceptions.iterator().next() instanceof FileProcessorException);
}
Aggregations