-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve queue job items and cleanup after some time #472
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
6bbccad
Continued work on queue UI=
srtfisher 95be9f6
Wrapping up the core of the queue UI
srtfisher 7c0f57f
Working table for queue UI
srtfisher 49aea65
Adding counts to the queue
srtfisher f99c5ca
Switch to use wp_count_posts for performance
srtfisher 067fec3
Style the row table
srtfisher e544cb6
Adding single view for queue job
srtfisher 2be61f0
Adding queue UI with fixes for retrying
srtfisher ce2f784
Serialize enums when asserting against them
srtfisher 28582f7
Keep queue job around after it is complete for logging
srtfisher b86a8b9
Merge branch 'queue-performance' into queue-ui
srtfisher 3a8a361
Merging in work
srtfisher c12792f
Fixing tests and adjusting comment
srtfisher 66f1e5e
Fixing linting
srtfisher c30bfca
Stubbing the cleanup command
srtfisher 8a8538d
Cleanup the processed/failed jobs after some time
srtfisher a45f006
Merging in queue-performance
srtfisher 1a21073
Fixing phpcs issue
srtfisher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Cleanup_Jobs_Commands class file. | ||
* | ||
* @package Mantle | ||
*/ | ||
|
||
namespace Mantle\Queue\Console; | ||
|
||
use Mantle\Console\Command; | ||
use Mantle\Contracts\Container; | ||
use Mantle\Queue\Events\Job_Processed; | ||
use Mantle\Queue\Events\Job_Processing; | ||
use Mantle\Queue\Events\Run_Complete; | ||
use Mantle\Queue\Events\Run_Start; | ||
use Mantle\Queue\Providers\WordPress\Post_Status; | ||
use Mantle\Queue\Providers\WordPress\Queue_Record; | ||
|
||
/** | ||
* Queue Cleanup Command | ||
*/ | ||
class Cleanup_Jobs_Command extends Command { | ||
/** | ||
* The console command name. | ||
* | ||
* @var string | ||
*/ | ||
protected $name = 'queue:cleanup'; | ||
/** | ||
* Command Description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Cleanup old queue jobs.'; | ||
|
||
/** | ||
* Command action. | ||
*/ | ||
public function handle() { | ||
Queue_Record::query() | ||
->whereStatus( [ Post_Status::FAILED->value, Post_Status::COMPLETED->value ] ) | ||
->olderThan( now()->subSeconds( (int) $this->container['config']->get( 'queue.delete_after', 60 ) ) ) | ||
->take( -1 ) | ||
->each_by_id( | ||
fn ( Queue_Record $record ) => $record->delete( true ), | ||
100, | ||
); | ||
} | ||
} |
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
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
9 changes: 3 additions & 6 deletions
9
...e/providers/wordpress/class-queue-job.php → ...roviders/wordpress/class-queue-record.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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class
Cleanup_Jobs_Command
is well-structured and follows good object-oriented design principles. It extends the baseCommand
class and defines properties and a method that are clear in their purpose. Thehandle
method uses a fluent interface to build a query, which is a common and readable way to interact with models in modern PHP frameworks.However, there are a few points to consider:
Post_Status::FAILED->value
,Post_Status::COMPLETED->value
) is a good practice for code clarity and maintainability. Ensure that the rest of the codebase is compatible with PHP 8 features if they are being used here.olderThan
method seems to be a custom addition to the query builder. Ensure that this method is properly defined and tested in theQueue_Record
model or query builder class.take(-1)
method call is unusual. Typically,take
is used to limit the number of records returned. If-1
is intended to indicate "all records," this should be clearly documented, as it's not a standard convention. If it's a mistake, it should be corrected.fn (Queue_Record $record) => $record->delete(true)
withineach_by_id
is concise and takes advantage of PHP 8's arrow functions. Ensure that thedelete
method onQueue_Record
accepts a boolean parameter and that its behavior is well-documented, especially what passingtrue
signifies.handle
method. Consider what should happen if the deletion fails for one or moreQueue_Record
instances. Should the command fail entirely, log an error, or continue with the next record? This depends on the desired behavior and robustness of the command.delete_after
configuration value. Ensure that this configuration option is documented and validated elsewhere in the codebase.Here's a potential update to the
take
method if-1
is not intended:This change assumes that there's a configuration setting named
queue.cleanup_batch_size
that controls how many records should be processed at a time.Commitable suggestion