-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Make sure that disabled jobs are paused in Quartz #25408
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,7 @@ public QuartzScheduler(SchedulerContext context, QuartzSupport quartzSupport, Sc | |
String cron = SchedulerUtils.lookUpPropertyValue(scheduled.cron()); | ||
if (!cron.isEmpty()) { | ||
if (SchedulerUtils.isOff(cron)) { | ||
this.pause(identity); | ||
continue; | ||
} | ||
if (!CronType.QUARTZ.equals(cronType)) { | ||
|
@@ -214,6 +215,7 @@ public QuartzScheduler(SchedulerContext context, QuartzSupport quartzSupport, Sc | |
} else if (!scheduled.every().isEmpty()) { | ||
OptionalLong everyMillis = SchedulerUtils.parseEveryAsMillis(scheduled); | ||
if (!everyMillis.isPresent()) { | ||
this.pause(identity); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
continue; | ||
} | ||
SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.quarkus.it.quartz; | ||
|
||
import javax.inject.Inject; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
|
||
@Path("/scheduler/disabled") | ||
public class DisabledMethodResource { | ||
|
||
@Inject | ||
DisabledScheduledMethods disabledScheduledMethods; | ||
|
||
@GET | ||
@Path("cron") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String getCronCount() { | ||
return disabledScheduledMethods.valueSetByCronScheduledMethod; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You shouldn't access a static variable like this... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't give this much thought since it is a variable that's there to only show that it is not initialized. |
||
} | ||
|
||
@GET | ||
@Path("every") | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String getEveryCount() { | ||
return disabledScheduledMethods.valueSetByEveryScheduledMethod; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.it.quartz; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.scheduler.Scheduled; | ||
|
||
@ApplicationScoped | ||
public class DisabledScheduledMethods { | ||
volatile static String valueSetByCronScheduledMethod = ""; | ||
volatile static String valueSetByEveryScheduledMethod = ""; | ||
|
||
// This should never be called as the job is disabled | ||
@Scheduled(cron = "${disabled}", identity = "disabled-cron-counter") | ||
void setValueByCron() { | ||
valueSetByCronScheduledMethod = "cron"; | ||
} | ||
|
||
// This should never be called as the job is turned off | ||
@Scheduled(every = "${off}", identity = "disabled-every-counter") | ||
void setValueByEvery() { | ||
valueSetByEveryScheduledMethod = "every"; | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's pause the job disabled job to effectively let Quartz know that this should not be invoked in any way.
When the job is enabled/turned on, it'll be rescheduled and executed again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This results in a
org.quartz.Scheduler.pauseJob(JobKey)
invocation, right? What happens if the job does not exist yet? Is it a no-op?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the job does not exists, it is a no-op.
I'll add a test case in the integration test project to make sure we won't have a regression here.