-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve queue job items and cleanup after some time (#472)
* Continued work on queue UI= * Wrapping up the core of the queue UI * Working table for queue UI * Adding counts to the queue * Switch to use wp_count_posts for performance * Style the row table * Adding single view for queue job * Adding queue UI with fixes for retrying * Serialize enums when asserting against them * Keep queue job around after it is complete for logging * Fixing tests and adjusting comment * Fixing linting * Stubbing the cleanup command * Cleanup the processed/failed jobs after some time * Fixing phpcs issue
- Loading branch information
Showing
24 changed files
with
267 additions
and
96 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
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.