EventListerner on PROCESS_COMPLETED

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

Hi Erik,

What happens when there is another listener (after your current one), which adds events to the event log?

One of the possibilities can be to apply housekeeping as it is for history (e.g. once a day purge log table for completed processes).
Another asynchronously plan to delete all events related to the process.

Regards
Martin

Hi Martin!

I’ll implement some housekeeping instead. Seems those events are created by the engine when clearing out the process variables from the runtime-tables mainly. Tried some different approaches of “quite ugly” overrides of different handlers in the engine, but lets keep it simple with a daily cleaner job instead. :slight_smile:

Anyway thanks!
/Erik