-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#29498 Create NoRetryPolicy and DefaultRetryStrategy annotations
Added @NoRetryPolicy to explicitly define no-retry behavior for job processors. Introduced @DefaultRetryStrategy for marking the default retry strategy implementation. Updated relevant classes to utilize these annotations for better code readability and maintainability.
- Loading branch information
1 parent
e999e20
commit ff5a516
Showing
7 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
dotCMS/src/main/java/com/dotcms/jobs/business/error/NoRetryStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.dotcms.jobs.business.error; | ||
|
||
import com.dotcms.jobs.business.job.Job; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
/** | ||
* Implements a no-retry strategy for job processors that should never retry failed jobs. This | ||
* strategy always returns false for shouldRetry and maintains an empty set of non-retryable | ||
* exceptions since retries are never attempted. | ||
*/ | ||
@ApplicationScoped | ||
public class NoRetryStrategy implements RetryStrategy { | ||
|
||
@Override | ||
public boolean shouldRetry(Job job, Class<? extends Throwable> exceptionClass) { | ||
return false; // Never retry | ||
} | ||
|
||
@Override | ||
public long nextRetryDelay(Job job) { | ||
return 0; // Not used since retries never occur | ||
} | ||
|
||
@Override | ||
public int maxRetries() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean isNonRetryableException(Class<? extends Throwable> exceptionClass) { | ||
return true; // All exceptions are considered non-retryable | ||
} | ||
|
||
@Override | ||
public void addNonRetryableException(Class<? extends Throwable> exceptionClass) { | ||
// No-op since all exceptions are already non-retryable | ||
} | ||
|
||
@Override | ||
public Set<Class<? extends Throwable>> getNonRetryableExceptions() { | ||
return Collections.emptySet(); // No need to track specific exceptions | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
dotCMS/src/main/java/com/dotcms/jobs/business/processor/DefaultRetryStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.dotcms.jobs.business.processor; | ||
|
||
import static java.lang.annotation.ElementType.FIELD; | ||
import static java.lang.annotation.ElementType.METHOD; | ||
import static java.lang.annotation.ElementType.PARAMETER; | ||
import static java.lang.annotation.ElementType.TYPE; | ||
import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.Target; | ||
import javax.inject.Qualifier; | ||
|
||
/** | ||
* Qualifier annotation to identify the default retry strategy implementation. | ||
*/ | ||
@Qualifier | ||
@Retention(RUNTIME) | ||
@Target({TYPE, METHOD, FIELD, PARAMETER}) | ||
@Documented | ||
public @interface DefaultRetryStrategy { | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
dotCMS/src/main/java/com/dotcms/jobs/business/processor/NoRetryPolicy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.dotcms.jobs.business.processor; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Annotation to explicitly specify that a job processor should not retry failed jobs. | ||
* This provides a more semantic way to indicate no-retry behavior compared to setting | ||
* maxRetries=0 in ExponentialBackoffRetryPolicy. | ||
* | ||
* <p>Usage example:</p> | ||
* <pre> | ||
* {@literal @}NoRetryPolicy | ||
* {@literal @}Queue("myQueue") | ||
* public class MyJobProcessor implements JobProcessor { | ||
* // Implementation | ||
* } | ||
* </pre> | ||
*/ | ||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE}) | ||
public @interface NoRetryPolicy { | ||
// No elements needed - presence of annotation is sufficient | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters