Hi!
I am implementing a use-case where we should delete all data linked to a process from the event log table when the process completes. We use the event log during the lifetime of the process. We also use the data of the completed process after its finished but the events are not needed anymore and should be purged since the log takes a lot of space.
However after my eventlistener have executed and deleted like 300+ events, new events are being created by the process engine. (around 50 events) The last one being PROCESSINSTANCE_END
Please advice.
My eventlistener:
@Component
public class CleanupEventLogOnProcessEnd implements FlowableEventListener {
private static Logger log = LoggerFactory.getLogger(CleanupEventLogOnProcessEnd.class);
private final ManagementService managementService;
public CleanupEventLogOnProcessEnd(ManagementService managementService) {
this.managementService = managementService;
}
@Override
public void onEvent(FlowableEvent event) {
if(FlowableEngineEventType.PROCESS_CANCELLED.equals(event.getType()) || FlowableEngineEventType.PROCESS_COMPLETED.equals(event.getType())) {
FlowableEngineEvent flowableEndEvent = (FlowableEngineEvent) event;
log.info("Cleaning up event log for processInstanceId {} on process completion");
managementService.getEventLogEntriesByProcessInstanceId(flowableEndEvent.getProcessInstanceId())
.forEach(eventLogEntry ->
managementService.deleteEventLogEntry(eventLogEntry.getLogNumber()));
}
}
@Override
public boolean isFailOnException() {
return false;
}
@Override
public boolean isFireOnTransactionLifecycleEvent() {
return true;
}
@Override
public String getOnTransaction() {
return TransactionState.COMMITTED.name();
}
}