appwrite/src/Appwrite/Platform/Tasks/QueueRetry.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2024-01-04 13:00:25 +00:00
<?php
namespace Appwrite\Platform\Tasks;
use Utopia\CLI\Console;
use Utopia\Platform\Action;
2025-01-29 14:13:58 +00:00
use Utopia\Queue\Publisher;
use Utopia\Queue\Queue;
2024-10-08 07:54:40 +00:00
use Utopia\Validator\Text;
use Utopia\Validator\Wildcard;
2024-01-04 13:00:25 +00:00
2024-01-24 17:54:52 +00:00
class QueueRetry extends Action
2024-01-04 13:00:25 +00:00
{
public static function getName(): string
{
return 'queue-retry';
2024-01-04 13:00:25 +00:00
}
public function __construct()
{
$this
->desc('Retry failed jobs from a specific queue identified by the name parameter')
2024-04-18 09:09:39 +00:00
->param('name', '', new Text(100), 'Queue name')
2024-02-28 19:09:10 +00:00
->param('limit', 0, new Wildcard(), 'jobs limit', true)
2025-01-29 14:13:58 +00:00
->inject('publisher')
2025-03-12 11:25:48 +00:00
->callback([$this, 'action']);
2024-01-04 13:00:25 +00:00
}
/**
* @param string $name The name of the queue to retry jobs from
2024-02-28 19:01:42 +00:00
* @param mixed $limit
2025-01-29 14:13:58 +00:00
* @param Publisher $publisher
*/
2025-01-29 14:13:58 +00:00
public function action(string $name, mixed $limit, Publisher $publisher): void
2024-01-04 13:00:25 +00:00
{
if (!$name) {
Console::error('Missing required parameter $name');
return;
}
2024-02-28 19:09:10 +00:00
$limit = (int)$limit;
2024-01-24 17:44:29 +00:00
Console::log('Retrying failed jobs...');
2025-01-29 14:13:58 +00:00
$publisher->retry(new Queue($name), $limit);
2024-01-04 13:00:25 +00:00
}
2024-01-04 13:04:51 +00:00
}