2024-01-04 13:00:25 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Platform\Tasks;
|
|
|
|
|
|
|
|
|
|
use Utopia\CLI\Console;
|
|
|
|
|
use Utopia\Platform\Action;
|
|
|
|
|
use Utopia\Queue\Client;
|
|
|
|
|
use Utopia\Queue\Connection;
|
|
|
|
|
use Utopia\Validator\Text;
|
|
|
|
|
|
|
|
|
|
class Retry extends Action
|
|
|
|
|
{
|
|
|
|
|
public static function getName(): string
|
|
|
|
|
{
|
2024-01-19 13:18:37 +00:00
|
|
|
return 'retry-jobs';
|
2024-01-04 13:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this
|
2024-01-19 13:18:37 +00:00
|
|
|
->desc('Retry failed jobs from a specific queue identified by the name parameter')
|
2024-01-04 13:00:25 +00:00
|
|
|
->param('name', '', new Text(128), 'Queue name')
|
|
|
|
|
->inject('queue')
|
2024-01-19 13:18:37 +00:00
|
|
|
->callback(fn ($name, $queue) => $this->action($name, $queue));
|
2024-01-04 13:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-19 13:18:37 +00:00
|
|
|
/**
|
|
|
|
|
* @param string $name The name of the queue to retry jobs from
|
|
|
|
|
* @param Connection $queue
|
|
|
|
|
*/
|
|
|
|
|
public function action(string $name, Connection $queue): void
|
2024-01-04 13:00:25 +00:00
|
|
|
{
|
2024-01-19 13:18:37 +00:00
|
|
|
if (!$name) {
|
|
|
|
|
Console::error('Missing required parameter $name');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$queueClient = new Client($name, $queue);
|
2024-01-04 13:00:25 +00:00
|
|
|
|
2024-01-19 13:18:37 +00:00
|
|
|
if ($queueClient->countFailedJobs() === 0) {
|
2024-01-05 12:37:03 +00:00
|
|
|
Console::error('No failed jobs found.');
|
2024-01-04 13:00:25 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$queueClient->retry();
|
|
|
|
|
}
|
2024-01-04 13:04:51 +00:00
|
|
|
}
|