96 lines
2.3 KiB
PHP
96 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Entity;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
#[ORM\Entity]
|
|
#[ORM\Table(name: 'tag_rebuild_job')]
|
|
#[ORM\Index(columns: ['status'], name: 'idx_tag_rebuild_job_status')]
|
|
#[ORM\Index(columns: ['created_at'], name: 'idx_tag_rebuild_job_created_at')]
|
|
class TagRebuildJob
|
|
{
|
|
public const STATUS_QUEUED = 'QUEUED';
|
|
public const STATUS_RUNNING = 'RUNNING';
|
|
public const STATUS_COMPLETED = 'COMPLETED';
|
|
public const STATUS_FAILED = 'FAILED';
|
|
|
|
#[ORM\Id]
|
|
#[ORM\Column(type: 'uuid', unique: true)]
|
|
private Uuid $id;
|
|
|
|
#[ORM\Column(length: 16)]
|
|
private string $status = self::STATUS_QUEUED;
|
|
|
|
#[ORM\Column(type: 'datetime_immutable')]
|
|
private \DateTimeImmutable $createdAt;
|
|
|
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
|
private ?\DateTimeImmutable $startedAt = null;
|
|
|
|
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
|
|
private ?\DateTimeImmutable $finishedAt = null;
|
|
|
|
#[ORM\Column(type: 'text', nullable: true)]
|
|
private ?string $errorMessage = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->id = Uuid::v4();
|
|
$this->createdAt = new \DateTimeImmutable();
|
|
$this->status = self::STATUS_QUEUED;
|
|
}
|
|
|
|
public function getId(): Uuid
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getStatus(): string
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function markRunning(): void
|
|
{
|
|
$this->status = self::STATUS_RUNNING;
|
|
$this->startedAt = new \DateTimeImmutable();
|
|
$this->errorMessage = null;
|
|
}
|
|
|
|
public function markCompleted(): void
|
|
{
|
|
$this->status = self::STATUS_COMPLETED;
|
|
$this->finishedAt = new \DateTimeImmutable();
|
|
}
|
|
|
|
public function markFailed(string $message): void
|
|
{
|
|
$this->status = self::STATUS_FAILED;
|
|
$this->finishedAt = new \DateTimeImmutable();
|
|
$this->errorMessage = $message;
|
|
}
|
|
|
|
public function getCreatedAt(): \DateTimeImmutable
|
|
{
|
|
return $this->createdAt;
|
|
}
|
|
|
|
public function getStartedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->startedAt;
|
|
}
|
|
|
|
public function getFinishedAt(): ?\DateTimeImmutable
|
|
{
|
|
return $this->finishedAt;
|
|
}
|
|
|
|
public function getErrorMessage(): ?string
|
|
{
|
|
return $this->errorMessage;
|
|
}
|
|
} |