Skip to content

Commit

Permalink
#29478 Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Aug 30, 2024
1 parent 77ac1a8 commit 7517ec9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,38 @@
* <pre>{@code
* public static void main(String[] args) {
*
* // Create the job queue
* JobQueue jobQueue = new PostgresJobQueue();
* // Create the job queue
* JobQueue jobQueue = new PostgresJobQueue();
*
* // Create and start the job queue manager
* JobQueueManagerAPIImpl jobQueueManagerAPI = new JobQueueManagerAPIImpl(jobQueue, 5); // 5 threads
* // Create and start the job queue manager
* JobQueueManagerAPIImpl jobQueueManagerAPI = new JobQueueManagerAPIImpl(jobQueue, 5); // 5 threads
*
* //(Optional) Set up a retry strategy for content import jobs
* RetryStrategy contentImportRetryStrategy = new ExponentialBackoffRetryStrategy(5000, 300000, 2.0, 3);
* contentImportRetryStrategy.addRetryableException(IOException.class);
* jobQueueManagerAPI.setRetryStrategy("contentImport", contentImportRetryStrategy);
* // (Optional) Set up a retry strategy for content import jobs, if not set, the default retry strategy will be used
* RetryStrategy contentImportRetryStrategy = new ExponentialBackoffRetryStrategy(
* 5000, 300000, 2.0, 3
* );
* contentImportRetryStrategy.addRetryableException(IOException.class);
* jobQueueManagerAPI.setRetryStrategy("contentImport", contentImportRetryStrategy);
*
* // Register job processors
* jobQueueManagerAPI.registerProcessor("contentImport", new ContentImportJobProcessor());
* // Register job processors
* jobQueueManagerAPI.registerProcessor("contentImport", new ContentImportJobProcessor());
*
* // Start the job queue manager
* jobQueueManagerAPI.start();
* // Start the job queue manager
* jobQueueManagerAPI.start();
*
* // Create a content import job (dummy example)
* Map<String, Object> jobParameters = new HashMap<>();
* jobParameters.put("filePath", "/path/to/import/file.csv");
* jobParameters.put("contentType", "Article");
* String jobId = jobQueueManagerAPI.createJob("contentImport", jobParameters);
* // Create a content import job (dummy example)
* Map<String, Object> jobParameters = new HashMap<>();
* jobParameters.put("filePath", "/path/to/import/file.csv");
* jobParameters.put("contentType", "Article");
* String jobId = jobQueueManagerAPI.createJob("contentImport", jobParameters);
*
* // Optionally, watch the job progress
* jobQueueManagerAPI.watchJob(jobId, job -> {
* System.out.println("Job " + job.id() + " progress: " + job.progress() * 100 + "%");
* });
* // Optionally, watch the job progress
* jobQueueManagerAPI.watchJob(jobId, job -> {
* System.out.println("Job " + job.id() + " progress: " + job.progress() * 100 + "%");
* });
*
* // When shutting down the application
* jobQueueManagerAPI.close();
* // When shutting down the application
* jobQueueManagerAPI.close();
* }
* }</pre>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,23 +88,11 @@ public long nextRetryDelay(final Job job) {
return delay + jitter;
}

/**
* Returns the maximum number of retry attempts allowed by this strategy.
*
* @return The maximum number of retries.
*/
@Override
public int maxRetries() {
return maxRetries;
}

/**
* Determines whether a given exception is considered retryable according to the retry
* strategy.
*
* @param exception The exception to check if it is retryable.
* @return {@code true} if the exception is retryable, {@code false} otherwise.
*/
@Override
public boolean isRetryableException(final Throwable exception) {
if (exception == null) {
Expand All @@ -116,20 +104,12 @@ public boolean isRetryableException(final Throwable exception) {
return retryableExceptions.stream().anyMatch(clazz -> clazz.isInstance(exception));
}

/**
* Adds an exception class to the set of retryable exceptions.
*
* @param exceptionClass The exception class to be considered retryable.
*/
@Override
public void addRetryableException(final Class<? extends Throwable> exceptionClass) {
retryableExceptions.add(exceptionClass);
}

/**
* Returns an unmodifiable set of the currently registered retryable exceptions.
*
* @return An unmodifiable set of retryable exception classes.
*/
@Override
public Set<Class<? extends Throwable>> getRetryableExceptions() {
return Collections.unmodifiableSet(retryableExceptions);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotcms.jobs.business.error;

import com.dotcms.jobs.business.job.Job;
import java.util.Set;

/**
* Defines the contract for retry strategies in the job processing system. Implementations of this
Expand Down Expand Up @@ -40,4 +41,19 @@ public interface RetryStrategy {
* @return true if the exception is retryable, false otherwise.
*/
boolean isRetryableException(Throwable exception);

/**
* Adds an exception class to the set of retryable exceptions.
*
* @param exceptionClass The exception class to be considered retryable.
*/
void addRetryableException(final Class<? extends Throwable> exceptionClass);

/**
* Returns an unmodifiable set of the currently registered retryable exceptions.
*
* @return An unmodifiable set of retryable exception classes.
*/
Set<Class<? extends Throwable>> getRetryableExceptions();

}

0 comments on commit 7517ec9

Please sign in to comment.