Cleanup of cli

This commit is contained in:
2023-06-09 00:54:34 -04:00
parent 9307ba330c
commit 03c1dac2f2
36 changed files with 614 additions and 272 deletions

View File

@ -3,29 +3,31 @@ namespace ProVM\Emails\Model;
use DateTimeInterface;
use ProVM\Common\Define\Model;
use ProVM\Common\Exception\Database\BlankResult;
use ProVM\Common\Exception\Job\Stateless;
use ProVM\Emails;
class Job implements Model
{
protected int $id;
protected Message $message;
protected DateTimeInterface $dateTime;
protected bool $executed;
protected string $command;
protected string $arguments;
public function getId(): int
{
return $this->id;
}
public function getMessage(): Message
public function getCommand(): string
{
return $this->message;
return $this->command;
}
public function getDateTime(): DateTimeInterface
public function getArguments(): string
{
return $this->dateTime;
return $this->arguments ?? '';
}
public function isExecuted(): bool
{
return $this->executed ?? false;
return $this->lastState()->getStatus() === State\Job::Executed;
}
public function setId(int $id): Job
@ -33,22 +35,61 @@ class Job implements Model
$this->id = $id;
return $this;
}
public function setMessage(Message $message): Job
public function setCommand(string $message): Job
{
$this->message = $message;
return $this;
}
public function setDateTime(DateTimeInterface $dateTime): Job
public function setArguments(string $dateTime): Job
{
$this->dateTime = $dateTime;
return $this;
}
public function wasExecuted(): Job
protected Emails\Repository\State\Job $stateRepository;
public function getStateRepository(): Emails\Repository\State\Job
{
$this->executed = true;
return $this->stateRepository;
}
public function setStateRepository(Emails\Repository\State\Job $repository): Job
{
$this->stateRepository = $repository;
return $this;
}
protected array $states;
public function getStates(): array
{
if (!isset($this->states)) {
try {
$this->setStates($this->getStateRepository()->fetchByJob($this->getId()));
} catch (BlankResult $e) {
return [];
}
}
return $this->states;
}
public function addState(State\Job $state): Job
{
$this->states []= $state;
return $this;
}
public function setStates(array $states): Job
{
foreach ($states as $state) {
$this->addState($state);
}
return $this;
}
public function lastState(): State\Job
{
if (count($this->getStates()) === 0) {
throw new Stateless($this);
}
return $this->getStates()[array_key_last($this->getStates())];
}
public function toArray(): array
{
return [

View File

@ -0,0 +1,65 @@
<?php
namespace ProVM\Emails\Model\State;
use ProVM\Common\Define\Model;
use ProVM\Emails;
class Job implements Model
{
const Executed = 0;
const Pending = 1;
const Failure = -1;
protected int $id;
protected Emails\Model\Job $job;
protected \DateTimeInterface $dateTime;
protected int $status;
public function getId(): int
{
return $this->id;
}
public function getJob(): Emails\Model\Job
{
return $this->job;
}
public function getDateTime(): \DateTimeInterface
{
return $this->dateTime;
}
public function getStatus(): int
{
return $this->status;
}
public function setId(int $id): Job
{
$this->id = $id;
return $this;
}
public function setJob(Emails\Model\Job $job): Job
{
$this->job = $job;
return $this;
}
public function setDateTime(\DateTimeInterface $dateTime): Job
{
$this->dateTime = $dateTime;
return $this;
}
public function setStatus(int $status): Job
{
$this->status = $status;
return $this;
}
public function jsonSerialize(): mixed
{
return [
'id' => $this->getId(),
'job' => $this->getJob(),
'date' => $this->getDateTime(),
'status' => $this->getStatus()
];
}
}