parameters)
*/
Job getJob(String jobId) throws JobNotFoundException, JobQueueDataException;
+ /**
+ * Retrieves the current state of a specific job.
+ *
+ * If only the status is required, this method has better performance than
+ * {@link #getJob(String)} as it uses a cache that is only cleared on status changes, whereas
+ * {@link #getJob(String)} uses a cache that is cleared on any job change.
+ *
+ * @param jobId The ID of the job whose state is being queried.
+ * @return The current state of the job as a JobState enum.
+ * @throws JobNotFoundException if the job with the given ID is not found.
+ * @throws JobQueueDataException if there's a data storage error while fetching the job state.
+ */
+ JobState getJobState(final String jobId) throws JobNotFoundException, JobQueueDataException;
+
/**
* Retrieves a list of active jobs for a specific queue.
*
@@ -176,10 +190,10 @@ List getUpdatedJobsSince(Set jobIds, LocalDateTime since)
* Checks if a job has ever been in a specific state.
*
* @param jobId The ID of the job to check.
- * @param state The state to check for.
+ * @param states The states to check for.
* @return true if the job has been in the specified state, false otherwise.
* @throws JobQueueDataException if there's an error accessing the job data.
*/
- boolean hasJobBeenInState(String jobId, JobState state) throws JobQueueDataException;
+ boolean hasJobBeenInState(String jobId, JobState... states) throws JobQueueDataException;
}
\ No newline at end of file
diff --git a/dotCMS/src/main/java/com/dotcms/jobs/business/queue/PostgresJobQueue.java b/dotCMS/src/main/java/com/dotcms/jobs/business/queue/PostgresJobQueue.java
index dfc179106563..10298c44e578 100644
--- a/dotCMS/src/main/java/com/dotcms/jobs/business/queue/PostgresJobQueue.java
+++ b/dotCMS/src/main/java/com/dotcms/jobs/business/queue/PostgresJobQueue.java
@@ -8,9 +8,11 @@
import com.dotcms.jobs.business.queue.error.JobQueueDataException;
import com.dotcms.jobs.business.queue.error.JobQueueException;
import com.dotmarketing.business.APILocator;
+import com.dotmarketing.business.CacheLocator;
import com.dotmarketing.common.db.DotConnect;
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.util.Logger;
+import com.dotmarketing.util.UtilMethods;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -148,7 +150,7 @@ public class PostgresJobQueue implements JobQueue {
+ " WHERE id = ?";
private static final String HAS_JOB_BEEN_IN_STATE_QUERY = "SELECT "
- + "EXISTS (SELECT 1 FROM job_history WHERE job_id = ? AND state = ?)";
+ + "EXISTS (SELECT 1 FROM job_history WHERE job_id = ? AND state IN $??$)";
private static final String COLUMN_TOTAL_COUNT = "total_count";
@@ -224,6 +226,12 @@ public String createJob(final String queueName, final Map parame
@Override
public Job getJob(final String jobId) throws JobNotFoundException, JobQueueDataException {
+ // Check cache first
+ Job job = CacheLocator.getJobCache().get(jobId);
+ if (UtilMethods.isSet(job)) {
+ return job;
+ }
+
try {
DotConnect dc = new DotConnect();
dc.setSQL(SELECT_JOB_BY_ID_QUERY);
@@ -231,7 +239,13 @@ public Job getJob(final String jobId) throws JobNotFoundException, JobQueueDataE
List