Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into issue-30545-Refactor-…
Browse files Browse the repository at this point in the history
…Migrate-JobProcessor-Discovery-from-Jandex-to-CDI

# Conflicts:
#	dotCMS/src/main/java/com/dotcms/rest/api/v1/content/dotimport/ContentImportHelper.java
  • Loading branch information
jgambarios committed Dec 9, 2024
2 parents 085eb37 + fc6ec2a commit 9d0b4de
Show file tree
Hide file tree
Showing 16 changed files with 2,492 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ private String getJSCode(final Host currentHost, final HttpServletRequest reques

final StringBuilder builder = new StringBuilder(this.jsCode.get());

Map.of("${jitsu_key}", this.analyticsKeyFunction.apply(currentHost),
"${site}", request.getScheme() + "://" + request.getLocalName() + ":" + request.getLocalPort())
Map.of("${jitsu_key}", this.analyticsKeyFunction.apply(currentHost))
.forEach((key, value) -> {

int start;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,78 @@ String createJob(String queueName, Map<String, Object> parameters)
JobPaginatedResult getActiveJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of completed jobs for a specific queue.
*
* @param queueName The name of the queue
* @param page The page number
* @param pageSize The number of jobs per page
* @return A result object containing the list of completed jobs and pagination information.
* @throws DotDataException if there's an error fetching the jobs
*/
JobPaginatedResult getCompletedJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of canceled jobs for a specific queue.
*
* @param queueName The name of the queue
* @param page The page number
* @param pageSize The number of jobs per page
* @return A result object containing the list of canceled jobs and pagination information.
* @throws DotDataException if there's an error fetching the jobs
*/
JobPaginatedResult getCanceledJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of failed jobs for a specific queue.
*
* @param queueName The name of the queue
* @param page The page number
* @param pageSize The number of jobs per page
* @return A result object containing the list of failed jobs and pagination information.
* @throws DotDataException if there's an error fetching the jobs
*/
JobPaginatedResult getFailedJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of abandoned jobs for a specific queue.
*
* @param queueName The name of the queue
* @param page The page number
* @param pageSize The number of jobs per page
* @return A result object containing the list of abandoned jobs and pagination information.
* @throws DotDataException if there's an error fetching the jobs
*/
JobPaginatedResult getAbandonedJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of successful jobs for a specific queue.
*
* @param queueName The name of the queue
* @param page The page number
* @param pageSize The number of jobs per page
* @return A result object containing the list of successful jobs and pagination information.
* @throws DotDataException if there's an error fetching the jobs
*/
JobPaginatedResult getSuccessfulJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of all jobs for a specific queue.
*
* @param queueName The name of the queue
* @param page The page number
* @param pageSize The number of jobs per page
* @return A result object containing the list of jobs and pagination information.
* @throws DotDataException if there's an error fetching the jobs
*/
JobPaginatedResult getJobs(String queueName, int page, int pageSize)
throws DotDataException;

/**
* Retrieves a list of jobs.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,73 @@ public JobPaginatedResult getActiveJobs(final String queueName, final int page,
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getCompletedJobs(final String queueName, final int page, final int pageSize)
throws DotDataException {
try {
return jobQueue.getCompletedJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
throw new DotDataException("Error fetching completed jobs", e);
}
}


@CloseDBIfOpened
@Override
public JobPaginatedResult getCanceledJobs(final String queueName, final int page, final int pageSize)
throws DotDataException {
try {
return jobQueue.getCanceledJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
throw new DotDataException("Error fetching completed jobs", e);
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getFailedJobs(final String queueName, final int page, final int pageSize)
throws DotDataException {
try {
return jobQueue.getFailedJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
throw new DotDataException("Error fetching failed jobs", e);
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getAbandonedJobs(final String queueName, final int page, final int pageSize)
throws DotDataException {
try {
return jobQueue.getAbandonedJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
throw new DotDataException("Error fetching abandoned jobs", e);
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getSuccessfulJobs(final String queueName, final int page, final int pageSize)
throws DotDataException {
try {
return jobQueue.getSuccessfulJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
throw new DotDataException("Error fetching successful jobs", e);
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getJobs(final String queueName, final int page, final int pageSize)
throws DotDataException {
try {
return jobQueue.getJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
throw new DotDataException("Error fetching jobs", e);
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getJobs(final int page, final int pageSize) throws DotDataException {
Expand Down
73 changes: 73 additions & 0 deletions dotCMS/src/main/java/com/dotcms/jobs/business/queue/JobQueue.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,67 @@ String createJob(String queueName, Map<String, Object> parameters)
JobPaginatedResult getActiveJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;

/**
* Retrieves a list of completed jobs for a specific queue.
*
* @param queueName The name of the queue.
* @param page The page number (for pagination).
* @param pageSize The number of items per page.
* @return A result object containing the list of completed jobs and pagination information.
* @throws JobQueueDataException if there's a data storage error while fetching the jobs
*/
JobPaginatedResult getCompletedJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;

/**
* Retrieves a list of canceled jobs for a specific queue.
*
* @param queueName The name of the queue.
* @param page The page number (for pagination).
* @param pageSize The number of items per page.
* @return A result object containing the list of canceled jobs and pagination information.
* @throws JobQueueDataException if there's a data storage error while fetching the jobs
*/
JobPaginatedResult getCanceledJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;

/**
* Retrieves a list of failed jobs for a specific queue.
*
* @param queueName The name of the queue.
* @param page The page number (for pagination).
* @param pageSize The number of items per page.
* @return A result object containing the list of failed jobs and pagination information.
* @throws JobQueueDataException if there's a data storage error while fetching the jobs
*/
JobPaginatedResult getFailedJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;


/**
* Retrieves a list of abandoned jobs for a specific queue.
*
* @param queueName The name of the queue.
* @param page The page number (for pagination).
* @param pageSize The number of items per page.
* @return A result object containing the list of abandoned jobs and pagination information.
* @throws JobQueueDataException if there's a data storage error while fetching the jobs
*/
JobPaginatedResult getAbandonedJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;

/**
* Retrieves a list of successful jobs for a specific queue.
*
* @param queueName The name of the queue.
* @param page The page number (for pagination).
* @param pageSize The number of items per page.
* @return A result object containing the list of successful jobs and pagination information.
* @throws JobQueueDataException if there's a data storage error while fetching the jobs
*/
JobPaginatedResult getSuccessfulJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;

/**
* Retrieves a list of completed jobs for a specific queue within a date range.
*
Expand All @@ -92,6 +153,18 @@ JobPaginatedResult getCompletedJobs(String queueName, LocalDateTime startDate,
*/
JobPaginatedResult getJobs(int page, int pageSize) throws JobQueueDataException;

/**
* Retrieves a list of all jobs for a specific queue.
*
* @param queueName The name of the queue.
* @param page The page number (for pagination).
* @param pageSize The number of items per page.
* @return A result object containing the list of jobs and pagination information.
* @throws JobQueueDataException if there's a data storage error while fetching the jobs
*/
JobPaginatedResult getJobs(String queueName, int page, int pageSize)
throws JobQueueDataException;

/**
* Retrieves a list of active jobs, meaning jobs that are currently being processed.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ public class PostgresJobQueue implements JobQueue {
"FROM total t " +
"LEFT JOIN paginated_data p ON true";

private static final String GET_JOBS_FOR_QUEUE_QUERY =
"WITH total AS (" +
" SELECT COUNT(*) AS total_count " +
" FROM job " +
" WHERE queue_name = ? " +
"), " +
"paginated_data AS (" +
" SELECT * " +
" FROM job " +
" WHERE queue_name = ? " +
" ORDER BY created_at DESC " +
" LIMIT ? OFFSET ? " +
") " +
"SELECT p.*, t.total_count " +
"FROM total t " +
"LEFT JOIN paginated_data p ON true";


private static final String GET_UPDATED_JOBS_SINCE_QUERY = "SELECT * FROM job "
+ "WHERE id = ANY(?) AND updated_at > ?";

Expand Down Expand Up @@ -309,8 +327,8 @@ public JobState getJobState(final String jobId)

@CloseDBIfOpened
@Override
public JobPaginatedResult getActiveJobs(final String queueName, final int page,
final int pageSize) throws JobQueueDataException {
public JobPaginatedResult getActiveJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

return getJobsByState(JobStateQueryParameters.builder()
.queueName(queueName)
Expand All @@ -323,6 +341,78 @@ public JobPaginatedResult getActiveJobs(final String queueName, final int page,
);
}


@CloseDBIfOpened
@Override
public JobPaginatedResult getCompletedJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

return getJobsByState(JobStateQueryParameters.builder()
.queueName(queueName)
.page(page)
.pageSize(pageSize)
.orderByColumn(COLUMN_COMPLETED_AT)
.states(JobState.SUCCESS, JobState.CANCELED,
JobState.ABANDONED_PERMANENTLY, JobState.FAILED_PERMANENTLY).build()
);
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getCanceledJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

return getJobsByState(JobStateQueryParameters.builder()
.queueName(queueName)
.page(page)
.pageSize(pageSize)
.orderByColumn(COLUMN_UPDATED_AT)
.states(JobState.CANCEL_REQUESTED, JobState.CANCELLING, JobState.CANCELED).build()
);
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getFailedJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

return getJobsByState(JobStateQueryParameters.builder()
.queueName(queueName)
.page(page)
.pageSize(pageSize)
.orderByColumn(COLUMN_UPDATED_AT)
.states(JobState.FAILED, JobState.FAILED_PERMANENTLY).build()
);
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getAbandonedJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

return getJobsByState(JobStateQueryParameters.builder()
.queueName(queueName)
.page(page)
.pageSize(pageSize)
.orderByColumn(COLUMN_UPDATED_AT)
.states(JobState.ABANDONED, JobState.ABANDONED_PERMANENTLY).build()
);
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getSuccessfulJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

return getJobsByState(JobStateQueryParameters.builder()
.queueName(queueName)
.page(page)
.pageSize(pageSize)
.orderByColumn(COLUMN_COMPLETED_AT)
.states(JobState.SUCCESS).build()
);
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getCompletedJobs(final String queueName,
Expand All @@ -343,6 +433,26 @@ public JobPaginatedResult getCompletedJobs(final String queueName,
);
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getJobs(final String queueName, final int page, final int pageSize)
throws JobQueueDataException {

try {
DotConnect dc = new DotConnect();
dc.setSQL(GET_JOBS_FOR_QUEUE_QUERY);
dc.addParam(queueName);
dc.addParam(queueName);
dc.addParam(pageSize);
dc.addParam((page - 1) * pageSize);

return jobPaginatedResult(page, pageSize, dc);
} catch (DotDataException e) {
Logger.error(this, "Database error while fetching jobs for queue: " + queueName, e);
throw new JobQueueDataException("Database error while fetching jobs for queue: " + queueName, e);
}
}

@CloseDBIfOpened
@Override
public JobPaginatedResult getJobs(final int page, final int pageSize)
Expand Down
Loading

0 comments on commit 9d0b4de

Please sign in to comment.