Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit Job early when the Pollable Task is already finished #964

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,33 +46,40 @@ public void execute(JobExecutionContext context) throws JobExecutionException {
Long pollableTaskId = context.getMergedJobDataMap().getLong(POLLABLE_TASK_ID);
currentPollableTask = pollableTaskService.getPollableTask(pollableTaskId);

ExceptionHolder exceptionHolder = new ExceptionHolder(currentPollableTask);

try {
I callInput;

String inputStringFromJob = context.getMergedJobDataMap().getString(INPUT);

if (inputStringFromJob != null) {
logger.debug("Inlined data, read from job data");
callInput =
(I) objectMapper.readValueUnchecked(inputStringFromJob, typeTokenInput.getRawType());
} else {
logger.debug("No inlined data, read from blob storage");
callInput =
(I) pollableTaskBlobStorage.getInput(pollableTaskId, typeTokenInput.getRawType());
}

O callOutput = call(callInput);

if (!typeTokenOutput.getRawType().equals(Void.class)) {
pollableTaskBlobStorage.saveOutput(pollableTaskId, callOutput);
if (currentPollableTask.getFinishedDate() != null) {
logger.error(
"PollableTask is already finished. Suspected invalid retry (potential scheduler shutdown "
+ "after pollable was marked finished but befre Quartz job was recorded as finished)");
} else {
ExceptionHolder exceptionHolder = new ExceptionHolder(currentPollableTask);

try {
I callInput;

String inputStringFromJob = context.getMergedJobDataMap().getString(INPUT);

if (inputStringFromJob != null) {
logger.debug("Inlined data, read from job data");
callInput =
(I) objectMapper.readValueUnchecked(inputStringFromJob, typeTokenInput.getRawType());
} else {
logger.debug("No inlined data, read from blob storage");
callInput =
(I) pollableTaskBlobStorage.getInput(pollableTaskId, typeTokenInput.getRawType());
}

O callOutput = call(callInput);

if (!typeTokenOutput.getRawType().equals(Void.class)) {
pollableTaskBlobStorage.saveOutput(pollableTaskId, callOutput);
}
} catch (Throwable t) {
pollableTaskExceptionUtils.processException(t, exceptionHolder);
} finally {
currentPollableTask =
pollableTaskService.finishTask(
currentPollableTask.getId(), null, exceptionHolder, null);
}
} catch (Throwable t) {
pollableTaskExceptionUtils.processException(t, exceptionHolder);
} finally {
currentPollableTask =
pollableTaskService.finishTask(currentPollableTask.getId(), null, exceptionHolder, null);
}
}

Expand Down