Jobs setup
This commit is contained in:
@ -7,19 +7,17 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||
use ProVM\Service\Communicator;
|
||||
use function Safe\json_decode;
|
||||
use ProVM\Service\Mailboxes;
|
||||
|
||||
#[AsCommand(
|
||||
name: 'messages:grab',
|
||||
description: 'Run grab messages job for registered mailboxes',
|
||||
description: 'Run grab messages job for mailbox',
|
||||
hidden: false
|
||||
)]
|
||||
class Grab extends Command
|
||||
{
|
||||
public function __construct(Communicator $communicator, string $name = null)
|
||||
public function __construct(protected Mailboxes $service, string $name = null)
|
||||
{
|
||||
$this->setCommunicator($communicator);
|
||||
parent::__construct($name);
|
||||
}
|
||||
protected function configure()
|
||||
@ -27,27 +25,6 @@ class Grab extends Command
|
||||
$this->addArgument('mailbox_id', InputArgument::REQUIRED, 'Mailbox ID to grab emails');
|
||||
}
|
||||
|
||||
protected Communicator $communicator;
|
||||
public function getCommunicator(): Communicator
|
||||
{
|
||||
return $this->communicator;
|
||||
}
|
||||
public function setCommunicator(Communicator $communicator): Grab
|
||||
{
|
||||
$this->communicator = $communicator;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function grabMessages(int $mailbox_id): int
|
||||
{
|
||||
$response = $this->getCommunicator()->get("/mailbox/{$mailbox_id}/grab");
|
||||
$body = $response->getBody()->getContents();
|
||||
if (trim($body) === '') {
|
||||
return 0;
|
||||
}
|
||||
return json_decode($body)->messages->count;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$io = new SymfonyStyle($input, $output);
|
||||
@ -55,7 +32,7 @@ class Grab extends Command
|
||||
$mailbox_id = $input->getArgument('mailbox_id');
|
||||
$io->title("Grabbing Messages for Mailbox ID {$mailbox_id}");
|
||||
$io->section('Grabbing Messages');
|
||||
$count = $this->grabMessages($mailbox_id);
|
||||
$count = $this->service->grabMessages($mailbox_id);
|
||||
$io->info("Found {$count} messages");
|
||||
$io->success('Done.');
|
||||
|
||||
|
Reference in New Issue
Block a user