-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add failed jobs and requeue/delete commands
- Loading branch information
1 parent
05cd2e1
commit dbe3b8a
Showing
23 changed files
with
1,251 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
use Migrations\AbstractMigration; | ||
|
||
class CreateFailedJobs extends AbstractMigration | ||
{ | ||
/** | ||
* Change Method. | ||
* | ||
* More information on this method is available here: | ||
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method | ||
* @return void | ||
*/ | ||
public function change() | ||
{ | ||
$table = $this->table('failed_jobs'); | ||
$table->addColumn('class', 'string', [ | ||
'length' => 255, | ||
'null' => false, | ||
'default' => null, | ||
]) | ||
->addColumn('method', 'string', [ | ||
'length' => 255, | ||
'null' => false, | ||
'default' => null, | ||
]) | ||
->addColumn('data', 'text', [ | ||
'null' => false, | ||
'default' => null, | ||
]) | ||
->addColumn('config', 'string', [ | ||
'length' => 255, | ||
'null' => false, | ||
'default' => null, | ||
]) | ||
->addColumn('priority', 'string', [ | ||
'length' => 255, | ||
'null' => true, | ||
'default' => null, | ||
]) | ||
->addColumn('queue', 'string', [ | ||
'length' => 255, | ||
'null' => false, | ||
'default' => null, | ||
]) | ||
->addColumn('exception', 'text', [ | ||
'null' => true, | ||
'default' => null, | ||
]) | ||
->addColumn('created', 'datetime', [ | ||
'default' => null, | ||
'limit' => null, | ||
'null' => true, | ||
]) | ||
->create(); | ||
} | ||
} |
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,134 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org/) | ||
* @link https://cakephp.org CakePHP(tm) Project | ||
* @since 0.1.0 | ||
* @license https://opensource.org/licenses/MIT MIT License | ||
*/ | ||
namespace Cake\Queue\Command; | ||
|
||
use Cake\Command\Command; | ||
use Cake\Console\Arguments; | ||
use Cake\Console\ConsoleIo; | ||
use Cake\Console\ConsoleOptionParser; | ||
use Cake\ORM\Locator\LocatorAwareTrait; | ||
|
||
class DeleteCommand extends Command | ||
{ | ||
use LocatorAwareTrait; | ||
|
||
/** | ||
* Get the command name. | ||
* | ||
* @return string | ||
*/ | ||
public static function defaultName(): string | ||
{ | ||
return 'queue delete'; | ||
} | ||
|
||
/** | ||
* Gets the option parser instance and configures it. | ||
* | ||
* @return \Cake\Console\ConsoleOptionParser | ||
*/ | ||
public function getOptionParser(): ConsoleOptionParser | ||
{ | ||
$parser = parent::getOptionParser(); | ||
|
||
$parser->setDescription('Delete failed jobs.'); | ||
|
||
$parser->addArgument('ids', [ | ||
'required' => false, | ||
'help' => 'Delete jobs by the FailedJob ID (comma-separated).', | ||
]); | ||
$parser->addOption('class', [ | ||
'help' => 'Delete jobs by the job class.', | ||
]); | ||
$parser->addOption('queue', [ | ||
'help' => 'Delete jobs by the queue the job was received on.', | ||
]); | ||
$parser->addOption('config', [ | ||
'help' => 'Delete jobs by the config used to queue the job.', | ||
]); | ||
$parser->addOption('assume-yes', [ | ||
'help' => 'Automatically assume yes in response to confirmation prompt.', | ||
'short' => 'y', | ||
'boolean' => true, | ||
]); | ||
|
||
return $parser; | ||
} | ||
|
||
/** | ||
* @param \Cake\Console\Arguments $args Arguments | ||
* @param \Cake\Console\ConsoleIo $io ConsoleIo | ||
* @return void | ||
*/ | ||
public function execute(Arguments $args, ConsoleIo $io) | ||
{ | ||
/** @var \Cake\Queue\Model\Table\FailedJobsTable $failedJobsTable */ | ||
$failedJobsTable = $this->getTableLocator()->get('Cake/Queue.FailedJobs'); | ||
|
||
$jobsToDelete = $failedJobsTable->find(); | ||
|
||
if ($args->hasArgument('ids')) { | ||
$idsArg = $args->getArgument('ids'); | ||
|
||
if ($idsArg !== null) { | ||
$ids = explode(',', $idsArg); | ||
|
||
$jobsToDelete->whereInList($failedJobsTable->aliasField('id'), $ids); | ||
} | ||
} | ||
|
||
if ($args->hasOption('class')) { | ||
$jobsToDelete->where([ | ||
$failedJobsTable->aliasField('class') => $args->getOption('class'), | ||
]); | ||
} | ||
|
||
if ($args->hasOption('queue')) { | ||
$jobsToDelete->where([ | ||
$failedJobsTable->aliasField('queue') => $args->getOption('queue'), | ||
]); | ||
} | ||
|
||
if ($args->hasOption('config')) { | ||
$jobsToDelete->where([ | ||
$failedJobsTable->aliasField('config') => $args->getOption('config'), | ||
]); | ||
} | ||
|
||
$deletingCount = $jobsToDelete->count(); | ||
|
||
if (!$deletingCount) { | ||
$io->out('0 jobs found.'); | ||
|
||
return; | ||
} | ||
|
||
if (!$args->getOption('assume-yes')) { | ||
$confirmed = $io->askChoice("Delete {$deletingCount} jobs?", ['y', 'n'], 'n'); | ||
|
||
if ($confirmed !== 'y') { | ||
return; | ||
} | ||
} | ||
|
||
$io->out("Deleting {$deletingCount} jobs."); | ||
|
||
$failedJobsTable->deleteManyOrFail($jobsToDelete); | ||
|
||
$io->success("{$deletingCount} jobs deleted."); | ||
} | ||
} |
Oops, something went wrong.