Search in sources :

Example 1 with InsertQuery

use of sirius.db.jdbc.batch.InsertQuery in project sirius-biz by scireum.

the class EventRecorder method process.

/**
 * Processes the queued events by creating a {@link BatchContext} and batch-inserting all events.
 *
 * @return the number of inserted events
 */
protected int process() {
    lastProcessed = LocalDateTime.now();
    int processedEvents = 0;
    try (BatchContext ctx = new BatchContext(() -> "Process recorded events.", Duration.ofMinutes(1))) {
        Map<Class<? extends Event>, InsertQuery<Event>> queries = new HashMap<>();
        Event nextEvent = fetchBufferedEvent();
        while (nextEvent != null) {
            processEvent(ctx, queries, nextEvent);
            if (++processedEvents >= MAX_EVENTS_PER_PROCESS) {
                return processedEvents;
            }
            nextEvent = fetchBufferedEvent();
        }
    } catch (HandledException e) {
        Exceptions.ignore(e);
    } catch (Exception e) {
        Exceptions.handle(Log.BACKGROUND, e);
    }
    return processedEvents;
}
Also used : HandledException(sirius.kernel.health.HandledException) InsertQuery(sirius.db.jdbc.batch.InsertQuery) HashMap(java.util.HashMap) BatchContext(sirius.db.jdbc.batch.BatchContext) HandledException(sirius.kernel.health.HandledException)

Aggregations

HashMap (java.util.HashMap)1 BatchContext (sirius.db.jdbc.batch.BatchContext)1 InsertQuery (sirius.db.jdbc.batch.InsertQuery)1 HandledException (sirius.kernel.health.HandledException)1