All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ee.bitweb.core.scheduled.ScheduledJob Maven / Gradle / Ivy

There is a newer version: 4.0.0
Show newest version
package ee.bitweb.core.scheduled;

import ee.bitweb.core.trace.invoker.scheduler.SchedulerTraceIdResolver;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RequiredArgsConstructor
public abstract class ScheduledJob {

    private final T runnable;
    private final SchedulerTraceIdResolver traceIdResolver;

    public void run() {
        traceIdResolver.resolve();

        log.info("Started {}", getClass().getName());

        try {
            runnable.run();
        } catch (Exception e) {
           handleException(e);
        }

        log.info("Finished {}", getClass().getName());

        traceIdResolver.getContext().clear();
    }

    protected void handleException(Exception e) {
        log.error("{} failed: {}", getClass().getName(), e.getMessage(), e);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy