-
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.
#29479 Refactor job cancellation handling
Decoupled job cancellation logic by introducing a `Cancellable` interface. This improves clarity and separation of concerns, ensuring only processors capable of cancellation implement the relevant method. Updated existing tests to support the new interface and ensured compatibility with the JobQueueManagerAPI.
- Loading branch information
1 parent
fd872ba
commit a05c6ed
Showing
6 changed files
with
74 additions
and
31 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
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
39 changes: 39 additions & 0 deletions
39
dotCMS/src/main/java/com/dotcms/jobs/business/processor/Cancellable.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,39 @@ | ||
package com.dotcms.jobs.business.processor; | ||
|
||
import com.dotcms.jobs.business.error.JobCancellationException; | ||
import com.dotcms.jobs.business.job.Job; | ||
|
||
/** | ||
* The Cancellable interface represents a contract for objects that can be cancelled, | ||
* typically long-running operations or jobs. | ||
* <p> | ||
* Implementations of this interface should provide a mechanism to interrupt or | ||
* stop their execution in a controlled manner when the cancel method is invoked. | ||
* <p> | ||
* It's important to note that implementing this interface indicates that the object | ||
* supports cancellation. There is no separate method to check if cancellation is possible; | ||
* the presence of this interface implies that it is. | ||
*/ | ||
public interface Cancellable { | ||
|
||
/** | ||
* Attempts to cancel the execution of this object. | ||
* <p> | ||
* The exact behavior of this method depends on the specific implementation, | ||
* but it should generally attempt to stop the ongoing operation as quickly | ||
* and safely as possible. This might involve interrupting threads, closing | ||
* resources, or setting flags to stop loops. | ||
* <p> | ||
* Implementations should ensure that this method can be called safely from | ||
* another thread while the operation is in progress. | ||
* <p> | ||
* After this method is called, the object should make its best effort to | ||
* terminate, but there's no guarantee about when the termination will occur. | ||
* | ||
* @throws JobCancellationException if there is an error during the cancellation process. | ||
* This could occur if the job is in a state where it cannot be cancelled, | ||
* or if there's an unexpected error while attempting to cancel. | ||
*/ | ||
void cancel(Job job) throws JobCancellationException; | ||
|
||
} |
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
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