Search in sources :

Example 1 with JobWrapper

use of io.datarouter.job.scheduler.JobWrapper in project datarouter by hotpads.

the class JobStopperService method stopLocalJob.

// TODO licenses
private void stopLocalJob(String jobClassString, String username, Instant jobTriggerDeadline) {
    Class<? extends BaseJob> jobClass = BaseJob.parseClass(jobClassString);
    JobWrapper jobWrapper = localTriggerLockService.getForClass(jobClass);
    // job isn't running anymore
    if (jobWrapper == null) {
        return;
    }
    // the currently running job is not the one that the request was for
    if (jobWrapper.triggerTime.isAfter(jobTriggerDeadline)) {
        return;
    }
    jobWrapper.requestStop();
    // wait for job to gracefully stop itself
    ThreadTool.sleepUnchecked(JobScheduler.JOB_STOP_GRACE_PERIOD_MS);
    Future<Void> future = jobWrapper.getFuture();
    if (!future.isDone()) {
        future.cancel(true);
    }
    changelogRecorder.record(new DatarouterChangelogDtoBuilder("Job", jobClassString, "interrupt", username).build());
}
Also used : JobWrapper(io.datarouter.job.scheduler.JobWrapper) DatarouterChangelogDtoBuilder(io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)

Aggregations

DatarouterChangelogDtoBuilder (io.datarouter.instrumentation.changelog.ChangelogRecorder.DatarouterChangelogDtoBuilder)1 JobWrapper (io.datarouter.job.scheduler.JobWrapper)1