Skip to content

Commit

Permalink
Make Quartz jobs optionally recoverable
Browse files Browse the repository at this point in the history
Updates the QuartzJobInfo to include "requestRecovery" and use it when instantiating the Quartz job instances.  This allows to define each job to be recoverable independently.
  • Loading branch information
aurambaj committed Jul 28, 2023
1 parent cdbe42a commit 98b6029
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions webapp/src/main/java/com/box/l10n/mojito/quartz/QuartzJobInfo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.box.l10n.mojito.quartz;

import java.util.Date;
import org.quartz.JobBuilder;

public class QuartzJobInfo<I, O> {
Class<? extends QuartzPollableJob<I, O>> clazz;
Expand All @@ -12,6 +13,7 @@ public class QuartzJobInfo<I, O> {
String uniqueId;
boolean inlineInput;
long timeout;
boolean requestRecovery;

private QuartzJobInfo(Builder<I, O> builder) {
clazz = builder.clazz;
Expand All @@ -23,6 +25,7 @@ private QuartzJobInfo(Builder<I, O> builder) {
uniqueId = builder.uniqueId;
inlineInput = builder.inlineInput;
timeout = builder.timeout;
requestRecovery = builder.requestRecovery;
}

public Class<? extends QuartzPollableJob<I, O>> getClazz() {
Expand Down Expand Up @@ -61,6 +64,10 @@ public long getTimeout() {
return timeout;
}

public boolean getRequestRecovery() {
return requestRecovery;
}

public static <I, O> Builder<I, O> newBuilder(Class<? extends QuartzPollableJob<I, O>> clazz) {
Builder<I, O> builder = new Builder<I, O>();
builder.clazz = clazz;
Expand All @@ -77,6 +84,7 @@ public static final class Builder<I, O> {
private String uniqueId;
private boolean inlineInput = true;
private long timeout = 3600;
private boolean requestRecovery = false;

private Builder() {}

Expand Down Expand Up @@ -120,6 +128,12 @@ public Builder<I, O> withTimeout(long val) {
return this;
}

/** As defined in {@link JobBuilder#requestRecovery(boolean)} */
public Builder<I, O> withRequestRecovery(boolean requestRecovery) {
this.requestRecovery = requestRecovery;
return this;
}

public QuartzJobInfo<I, O> build() {
return new QuartzJobInfo<I, O>(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public <I, O> PollableFuture<O> scheduleJob(QuartzJobInfo<I, O> quartzJobInfo) {
if (jobDetail == null) {
logger.debug("Job doesn't exist, create for key: {}", keyName);
jobDetail =
JobBuilder.newJob().ofType(quartzJobInfo.getClazz()).withIdentity(jobKey).build();
JobBuilder.newJob()
.ofType(quartzJobInfo.getClazz())
.withIdentity(jobKey)
.requestRecovery(quartzJobInfo.getRequestRecovery())
.build();
}

logger.debug("Schedule a job for key: {}", keyName);
Expand Down

0 comments on commit 98b6029

Please sign in to comment.