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

fix(JobQueue) Fix on the info retrieved by the status endpoint Refs: #29480 #30386

Merged
merged 5 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class CircuitBreaker {

// The number of failures that will cause the circuit to open
static final int DEFAULT_CIRCUIT_BREAKER_FAILURE_THRESHOLD = Config.getIntProperty(
"DEFAULT_CIRCUIT_BREAKER_FAILURE_THRESHOLD", 5
"DEFAULT_CIRCUIT_BREAKER_FAILURE_THRESHOLD", 10
);

// The time in milliseconds after which to attempt to close the circuit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class RetryStrategyProducer {

// The maximum number of retry attempts allowed
static final int DEFAULT_RETRY_STRATEGY_MAX_RETRIES = Config.getIntProperty(
"DEFAULT_RETRY_STRATEGY_MAX_RETRIES", 3
"DEFAULT_RETRY_STRATEGY_MAX_RETRIES", 1
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.dotcms.jobs.business.processor.ProgressTracker;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -47,6 +48,7 @@ public interface AbstractJob {

Map<String, Object> parameters();

@JsonIgnore
Optional<ProgressTracker> progressTracker();

@Default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import graphql.VisibleForTesting;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.BeanParam;
import javax.ws.rs.Consumes;
Expand Down Expand Up @@ -68,21 +69,20 @@ public Response createJob(
@GET
@Path("/queues")
@Produces(MediaType.APPLICATION_JSON)
public Response getQueues(@Context HttpServletRequest request) {
public ResponseEntityView<Set<String>> getQueues(@Context HttpServletRequest request) {
new WebResource.InitBuilder(webResource)
.requiredBackendUser(true)
.requiredFrontendUser(false)
.requestAndResponse(request, null)
.rejectWhenNoUser(true)
.init();
return Response.ok(new ResponseEntityView<>(helper.getQueueNames())).build();

return new ResponseEntityView<>(helper.getQueueNames());
}

@GET
@Path("/{jobId}/status")
@Produces(MediaType.APPLICATION_JSON)
public Response getJobStatus(@Context HttpServletRequest request, @PathParam("jobId") String jobId)
public ResponseEntityView<Job> getJobStatus(@Context HttpServletRequest request, @PathParam("jobId") String jobId)
throws DotDataException {

new WebResource.InitBuilder(webResource)
Expand All @@ -93,21 +93,14 @@ public Response getJobStatus(@Context HttpServletRequest request, @PathParam("jo
.init();

Job job = helper.getJob(jobId);
Map<String, Object> statusInfo = Map.of(
"state", job.state(),
"progress", job.progress(),
"executionNode", job.executionNode().orElse("N/A")
);

return Response.ok(new ResponseEntityView<>(statusInfo)).build();

return new ResponseEntityView<>(job);
}

@POST
@Path("/{jobId}/cancel")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.WILDCARD)
public Response cancelJob(@Context HttpServletRequest request, @PathParam("jobId") String jobId)
public ResponseEntityView<String> cancelJob(@Context HttpServletRequest request, @PathParam("jobId") String jobId)
throws DotDataException {
new WebResource.InitBuilder(webResource)
.requiredBackendUser(true)
Expand All @@ -116,12 +109,12 @@ public Response cancelJob(@Context HttpServletRequest request, @PathParam("jobId
.rejectWhenNoUser(true)
.init();
helper.cancelJob(jobId);
return Response.ok(new ResponseEntityView<>("Job cancelled successfully")).build();
return new ResponseEntityView<>("Job cancelled successfully");
}

@GET
@Produces(MediaType.APPLICATION_JSON)
public Response listJobs(@Context HttpServletRequest request,
public ResponseEntityView <JobPaginatedResult> listJobs(@Context HttpServletRequest request,
@QueryParam("page") @DefaultValue("1") int page,
@QueryParam("pageSize") @DefaultValue("20") int pageSize) {
new WebResource.InitBuilder(webResource)
Expand All @@ -131,14 +124,13 @@ public Response listJobs(@Context HttpServletRequest request,
.rejectWhenNoUser(true)
.init();
final JobPaginatedResult result = helper.getJobs(page, pageSize);
return Response.ok(new ResponseEntityView<>(result)).build();

return new ResponseEntityView<>(result);
}

@GET
@Path("/{queueName}/active")
@Produces(MediaType.APPLICATION_JSON)
public Response activeJobs(@Context HttpServletRequest request, @PathParam("queueName") String queueName,
public ResponseEntityView<JobPaginatedResult> activeJobs(@Context HttpServletRequest request, @PathParam("queueName") String queueName,
@QueryParam("page") @DefaultValue("1") int page,
@QueryParam("pageSize") @DefaultValue("20") int pageSize) {
new WebResource.InitBuilder(webResource)
Expand All @@ -148,14 +140,13 @@ public Response activeJobs(@Context HttpServletRequest request, @PathParam("queu
.rejectWhenNoUser(true)
.init();
final JobPaginatedResult result = helper.getActiveJobs(queueName, page, pageSize);
return Response.ok(new ResponseEntityView<>(result)).build();

return new ResponseEntityView<>(result);
}

@GET
@Path("/failed")
@Produces(MediaType.APPLICATION_JSON)
public Response failedJobs(@Context HttpServletRequest request,
public ResponseEntityView<JobPaginatedResult> failedJobs(@Context HttpServletRequest request,
@QueryParam("page") @DefaultValue("1") int page,
@QueryParam("pageSize") @DefaultValue("20") int pageSize) {
new WebResource.InitBuilder(webResource)
Expand All @@ -165,7 +156,7 @@ public Response failedJobs(@Context HttpServletRequest request,
.rejectWhenNoUser(true)
.init();
final JobPaginatedResult result = helper.getFailedJobs(page, pageSize);
return Response.ok(new ResponseEntityView<>(result)).build();
return new ResponseEntityView<>(result);
}


Expand Down
Loading