use of io.automatiko.engine.api.auth.TrustedIdentityProvider in project automatiko-engine by automatiko-io.
the class Controller method cleanup.
@Override
public DeleteControl cleanup($DataType$ resource, Context context) {
try {
String trigger = "deleted";
IdentityProvider.set(new TrustedIdentityProvider("System<messaging>"));
io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
String correlation = resource.getMetadata().getName();
if (correlation != null) {
LOGGER.debug("Correlation ({}) is set, attempting to find if there is matching instance already active", correlation);
Optional<? extends ProcessInstance> possiblyFound = (Optional<? extends ProcessInstance>) process.instances().findById(correlation);
if (possiblyFound.isEmpty()) {
possiblyFound = (Optional<? extends ProcessInstance>) process.instances().findById(correlation, ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.MUTABLE);
}
possiblyFound.ifPresent(pi -> {
ProcessInstance pInstance = (ProcessInstance) pi;
LOGGER.debug("Found process instance {} matching correlation {}, signaling deletion to allow cleanup", pInstance.id(), correlation);
pInstance.send(Sig.of("Message-" + trigger, resource));
if (pInstance.status() == ProcessInstance.STATE_ACTIVE) {
LOGGER.debug("Instance is still active after signal, aborting...");
pInstance.abort();
}
});
return null;
}
return null;
});
} catch (Throwable t) {
LOGGER.error("Encountered problems while deleting instance", t);
}
return DeleteControl.defaultDelete();
}
Aggregations