class EventCleanupJob implements Job {

    @Override
    public void execute(final JobExecutionContext context) {
        LOGGER.info("Quartz triggered cleanup of database - event records.");
        final DateTime start = DateTime.now();

        try {
            final Date retention = this.calculateRetentionDate();
            final List<Event> oldEvents = this.transactionalEventService.getEventsBeforeDate(retention,
                    this.eventPageSize);
            if (!oldEvents.isEmpty()) {
                this.saveEventsToCsvFile(oldEvents);

                LOGGER.info("Deleting events...");
                this.transactionalEventService.deleteEvents(oldEvents);
            }
        } catch (final Exception e) {
            LOGGER.error("Exception during CSV file creation, compression or event deletion.", e);
        }

        final DateTime end = DateTime.now();
        LOGGER.info("Start: {}, end: {}, duration: {} milliseconds.", start, end, end.getMillis() - start.getMillis());
    }

}