-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5814 from WoltLab/unique-background-job
Unique background job
- Loading branch information
Showing
5 changed files
with
128 additions
and
11 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
56 changes: 56 additions & 0 deletions
56
wcfsetup/install/files/lib/system/background/job/AbstractUniqueBackgroundJob.class.php
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,56 @@ | ||
<?php | ||
|
||
namespace wcf\system\background\job; | ||
|
||
/** | ||
* This background job is only queued once | ||
* and is requeued when it has more work to do. | ||
* | ||
* @author Olaf Braun | ||
* @copyright 2001-2024 WoltLab GmbH | ||
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | ||
* @since 6.1 | ||
*/ | ||
abstract class AbstractUniqueBackgroundJob extends AbstractBackgroundJob | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
final public const MAX_FAILURES = 0; | ||
|
||
/** | ||
* Returns a unique identifier for this job. | ||
*/ | ||
public function identifier(): string | ||
{ | ||
return static::class; | ||
} | ||
|
||
/** | ||
* Returns a new instance of this job to be queued again. | ||
* This will reset the fail counter. | ||
*/ | ||
public function newInstance(): static | ||
{ | ||
return new static(); | ||
} | ||
|
||
/** | ||
* Returns whether this job should be queued again because it has more to do. | ||
*/ | ||
abstract public function queueAgain(): bool; | ||
|
||
#[\Override] | ||
final public function onFinalFailure() | ||
{ | ||
// onFailure() and onFinalFailure() are called at the same time. | ||
// Do your stuff in onFailure(). | ||
} | ||
|
||
#[\Override] | ||
public function retryAfter() | ||
{ | ||
// change the default value to 60 seconds | ||
return 60; | ||
} | ||
} |
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