Polish 'Add the ability to trigger a Quartz job through an Actuator endpoint'

See gh-43086
This commit is contained in:
Phillip Webb 2025-02-04 15:35:51 -08:00
parent fbeace397f
commit 9881f38d82
3 changed files with 8 additions and 51 deletions

View File

@ -156,6 +156,7 @@ The following table describes the structure of the response:
include::partial$rest/actuator/quartz/job-details/response-fields.adoc[]
[[quartz.trigger-job]]
== Trigger Quartz Job On Demand
@ -170,6 +171,7 @@ The response will look similar to the following:
include::partial$rest/actuator/quartz/trigger-job/http-response.adoc[]
[[quartz.trigger-job.request-structure]]
=== Request Structure
@ -190,6 +192,7 @@ The following table describes the structure of the response:
include::partial$rest/actuator/quartz/trigger-job/response-fields.adoc[]
[[quartz.trigger]]
== Retrieving Details of a Trigger

View File

@ -223,7 +223,10 @@ public class QuartzEndpoint {
* @since 3.5.0
*/
public QuartzJobTriggerDescriptor triggerQuartzJob(String groupName, String jobName) throws SchedulerException {
JobKey jobKey = JobKey.jobKey(jobName, groupName);
return triggerQuartzJob(JobKey.jobKey(jobName, groupName));
}
private QuartzJobTriggerDescriptor triggerQuartzJob(JobKey jobKey) throws SchedulerException {
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
return null;

View File

@ -43,7 +43,6 @@ import org.quartz.TriggerBuilder;
import org.quartz.TriggerKey;
import org.quartz.impl.matchers.GroupMatcher;
import org.springframework.boot.actuate.endpoint.ApiVersion;
import org.springframework.boot.actuate.endpoint.Show;
import org.springframework.boot.actuate.endpoint.web.test.WebEndpointTest;
import org.springframework.context.annotation.Bean;
@ -65,10 +64,6 @@ import static org.mockito.Mockito.mock;
*/
class QuartzEndpointWebIntegrationTests {
private static final String V2_JSON = ApiVersion.V2.getProducedMimeType().toString();
private static final String V3_JSON = ApiVersion.V3.getProducedMimeType().toString();
private static final JobDetail jobOne = JobBuilder.newJob(Job.class)
.withIdentity("jobOne", "samples")
.usingJobData(new JobDataMap(Collections.singletonMap("name", "test")))
@ -261,49 +256,6 @@ class QuartzEndpointWebIntegrationTests {
client.post()
.uri("/actuator/quartz/jobs/samples/jobOne")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.bodyValue(Map.of("state", "running"))
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("group")
.isEqualTo("samples")
.jsonPath("name")
.isEqualTo("jobOne")
.jsonPath("className")
.isEqualTo("org.quartz.Job")
.jsonPath("triggerTime")
.isNotEmpty();
}
@WebEndpointTest
void quartzTriggerJobV2(WebTestClient client) {
client.post()
.uri("/actuator/quartz/jobs/samples/jobOne")
.contentType(MediaType.parseMediaType(V2_JSON))
.accept(MediaType.APPLICATION_JSON)
.bodyValue(Map.of("state", "running"))
.exchange()
.expectStatus()
.isOk()
.expectBody()
.jsonPath("group")
.isEqualTo("samples")
.jsonPath("name")
.isEqualTo("jobOne")
.jsonPath("className")
.isEqualTo("org.quartz.Job")
.jsonPath("triggerTime")
.isNotEmpty();
}
@WebEndpointTest
void quartzTriggerJobV3(WebTestClient client) {
client.post()
.uri("/actuator/quartz/jobs/samples/jobOne")
.contentType(MediaType.parseMediaType(V3_JSON))
.accept(MediaType.APPLICATION_JSON)
.bodyValue(Map.of("state", "running"))
.exchange()
.expectStatus()
@ -334,8 +286,7 @@ class QuartzEndpointWebIntegrationTests {
void quartzTriggerJobWithUnknownState(WebTestClient client) {
client.post()
.uri("/actuator/quartz/jobs/samples/jobOne")
.contentType(MediaType.parseMediaType(V3_JSON))
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(Map.of("state", "unknown"))
.exchange()
.expectStatus()