Job time-outs
Cancel your jobs automatically if they take too long to complete
Do you have jobs that take forever due to some 3th party libraries that are unreliable? Or are your job executions sometimes stuck due to networking issues? With JobRunr Pro, you can have your jobs fail automatically if they take too long.
▶ See it in the live demo
Walk through Step 13 — The Hung Job in our hosted neobank demo. No install needed.
Open this step in the demo →Usage via @Job annotation
Using a job timeout is really easy, again thanks to the Job annotation. Just add the annotation to your service method and specify the job process timeout in ISO8601 Duration format:
@Job(processTimeOut = "PT5M")
public void jobCanBeInterruptedIfItTakesTooLong() {
System.out.println("This job will be interrupted if it stays longer than 5 minutes in PROCESSING state");
}
Usage via JobBuilder pattern
When you are using the JobBuilder pattern, you can pass the serverTag via the JobBuilder.
jobScheduler.create(aJob()
.withProcessTimeOut(Duration.ofMinutes(5))
.withJobLambda(() -> System.out.println("This will not run parallel as it is guarded by a mutex"));
ImportantIf your
Jobtimes out, it will go to theFAILEDstate automatically. Using the defaultJobconfiguration, it will automatically retry thanks to the exponential back-off policy. Depending on your business need, this may not be the desired and it can make sense to change the amount of retries to for example 0.
Configuration
Job time-outs don’t require any configuration.
External jobs and timeouts
External jobs can time out just like regular jobs, so they don’t remain in PROCESSED state indefinitely while waiting for a signal. The timeout countdown for external jobs begins the moment it starts processing (going into PROCESSING state) and continues as the job remains in PROCESSED state awaiting the external signal confirming its success or failure.
