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

ru.tinkoff.kora.scheduling.quartz.KoraQuartzJob Maven / Gradle / Ivy

There is a newer version: 1.1.16
Show newest version
package ru.tinkoff.kora.scheduling.quartz;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.Trigger;
import org.slf4j.MDC;
import ru.tinkoff.kora.common.Context;
import ru.tinkoff.kora.scheduling.common.telemetry.SchedulingTelemetry;

import java.util.function.Consumer;

public abstract class KoraQuartzJob implements Job {
    private final Consumer job;
    private final Trigger trigger;
    private final SchedulingTelemetry telemetry;

    public KoraQuartzJob(SchedulingTelemetry telemetry, Consumer job, Trigger trigger) {
        this.job = job;
        this.trigger = trigger;
        this.telemetry = telemetry;
    }

    @Override
    public final void execute(JobExecutionContext jobExecutionContext) {
        MDC.clear();
        Context.clear();

        var ctx = Context.current();
        var telemetryCtx = this.telemetry.get(ctx);
        try {
            this.job.accept(jobExecutionContext);
            telemetryCtx.close(null);
        } catch (Throwable e) {
            telemetryCtx.close(e);
            throw e;
        }
    }

    public Trigger getTrigger() {
        return this.trigger;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy