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

Re-execute after throwing exception incorrect docs #2303

Open
tompazourek opened this issue Mar 22, 2024 · 0 comments
Open

Re-execute after throwing exception incorrect docs #2303

tompazourek opened this issue Mar 22, 2024 · 0 comments

Comments

@tompazourek
Copy link

tompazourek commented Mar 22, 2024

Hi, I'm reading the docs (https://www.quartz-scheduler.net/documentation/best-practices.html#throwing-exceptions) and it contains this:

If a job throws an exception, Quartz will typically immediately re-execute it, meaning the job can and likely will throw the same exception again.

Is this actually true? I've been both testing this and reading the code, and it seems that when an exception occurs, the JobRunShell converts it to JobExecutionException with refireImmediately: false:

catch (Exception e)
{
endTime = qs.resources.TimeProvider.GetUtcNow();
logger.LogError(e, "Job {JobDetailKey} threw an unhandled Exception: ", jobDetail.Key);
SchedulerException se = new SchedulerException("Job threw an unhandled exception.", e);
string msg = $"Job {jec.JobDetail.Key} threw an exception.";
await qs.NotifySchedulerListenersError(msg, se, cancellationToken).ConfigureAwait(false);
jobExEx = new JobExecutionException(se, false);
}

The exception without refire will get converted to scheduler instruction (refireImmediately: false will convert to SchedulerInstruction.NoInstruction):

public virtual SchedulerInstruction ExecutionComplete(IJobExecutionContext context, JobExecutionException? result)
{
if (result != null && result.RefireImmediately)
{
return SchedulerInstruction.ReExecuteJob;
}
if (result != null && result.UnscheduleFiringTrigger)
{
return SchedulerInstruction.SetTriggerComplete;
}
if (result != null && result.UnscheduleAllTriggers)
{
return SchedulerInstruction.SetAllJobTriggersComplete;
}
if (!GetMayFireAgain())
{
return SchedulerInstruction.DeleteTrigger;
}
return SchedulerInstruction.NoInstruction;

This then means that the fired trigger will be marked as completed and no re-execution will happen. This is the opposite to what the documentation says.

Is this indended behavior? If yes, I think the documentation should be fixed. What do you think?

Thanks.

@tompazourek tompazourek changed the title Re-execute after throwing exception in docs Re-execute after throwing exception incorrect docs Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant