src/JanusHercules/HighVolumeProcess/Domain/Entity/HighVolumeProcess.php line 19

Open in your IDE?
  1. <?php
  2. namespace JanusHercules\HighVolumeProcess\Domain\Entity;
  3. use App\Utility\DatabaseIdGenerator;
  4. use App\Utility\DateTimeUtility;
  5. use DateTime;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Exception;
  9. use JanusHercules\HighVolumeProcess\Domain\Enum\ProcessStatus;
  10. use JanusHercules\HighVolumeProcess\Domain\Enum\ProcessType;
  11. use ValueError;
  12. #[ORM\Entity]
  13. #[ORM\Table(name: 'high_volume_processes')]
  14. #[ORM\Index(columns: ['process_status', 'finalization_started_at'], name: 'idx_process_status')]
  15. #[ORM\Index(columns: ['process_type', 'process_status'], name: 'idx_process_type_status')]
  16. class HighVolumeProcess
  17. {
  18. /**
  19. * @throws Exception
  20. */
  21. public function __construct(
  22. ProcessType $processType,
  23. string $processInfo = ''
  24. ) {
  25. if (mb_strlen($processInfo) > 255) {
  26. throw new ValueError('The processInfo cannot exceed 255 characters.');
  27. }
  28. $this->processType = $processType;
  29. $this->processStatus = ProcessStatus::CREATED;
  30. $this->createdAt = DateTimeUtility::createDateTimeUtc();
  31. $this->processInfo = $processInfo;
  32. }
  33. #[ORM\Id]
  34. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  35. #[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
  36. #[ORM\Column(
  37. type: Types::GUID,
  38. unique: true
  39. )]
  40. private ?string $id = null;
  41. public function getId(): ?string
  42. {
  43. return $this->id;
  44. }
  45. #[ORM\Column(
  46. type: Types::STRING,
  47. enumType: ProcessType::class
  48. )]
  49. private ProcessType $processType;
  50. public function getProcessType(): ProcessType
  51. {
  52. return $this->processType;
  53. }
  54. #[ORM\Column(
  55. type: Types::DATETIME_MUTABLE
  56. )]
  57. private DateTime $createdAt;
  58. public function getCreatedAt(): DateTime
  59. {
  60. return $this->createdAt;
  61. }
  62. #[ORM\Column(
  63. type : Types::DATETIME_MUTABLE,
  64. nullable: true
  65. )]
  66. private ?DateTime $lastUpdatedAt = null;
  67. public function setLastUpdatedAt(DateTime $lastUpdatedAt): void
  68. {
  69. $this->lastUpdatedAt = $lastUpdatedAt;
  70. }
  71. public function getLastUpdatedAt(): ?DateTime
  72. {
  73. return $this->lastUpdatedAt;
  74. }
  75. #[ORM\Column(
  76. type : Types::DATETIME_MUTABLE,
  77. nullable: true
  78. )]
  79. private ?DateTime $finishedAt = null;
  80. public function getFinishedAt(): ?DateTime
  81. {
  82. return $this->finishedAt;
  83. }
  84. public function setFinishedAt(?DateTime $finishedAt): void
  85. {
  86. $this->finishedAt = $finishedAt;
  87. }
  88. #[ORM\Column(
  89. type: Types::STRING,
  90. length: 255,
  91. )]
  92. private string $processInfo;
  93. public function getProcessInfo(): string
  94. {
  95. return $this->processInfo;
  96. }
  97. #[ORM\Column(
  98. type: Types::STRING,
  99. enumType: ProcessStatus::class
  100. )]
  101. private ProcessStatus $processStatus;
  102. public function getProcessStatus(): ProcessStatus
  103. {
  104. return $this->processStatus;
  105. }
  106. public function setProcessStatus(ProcessStatus $processStatus): void
  107. {
  108. $this->processStatus = $processStatus;
  109. }
  110. #[ORM\Column(
  111. type : Types::TEXT,
  112. nullable: true
  113. )]
  114. private ?string $errorMessage = null;
  115. public function getErrorMessage(): ?string
  116. {
  117. return $this->errorMessage;
  118. }
  119. public function setErrorMessage(string $errorMessage): void
  120. {
  121. $this->errorMessage = mb_substr($errorMessage, 0, 1024);
  122. }
  123. #[ORM\Column(
  124. type : Types::INTEGER,
  125. nullable: false
  126. )]
  127. private int $numberOfItemsToProcess = 0;
  128. public function getNumberOfItemsToProcess(): int
  129. {
  130. return $this->numberOfItemsToProcess;
  131. }
  132. public function setNumberOfItemsToProcess(
  133. int $numberOfItemsToProcess
  134. ): void {
  135. if ($numberOfItemsToProcess < 0) {
  136. throw new ValueError('numberOfItemsToProcess must be greater than 0.');
  137. }
  138. $this->numberOfItemsToProcess = $numberOfItemsToProcess;
  139. }
  140. #[ORM\Column(
  141. type : Types::INTEGER,
  142. nullable: false
  143. )]
  144. private int $numberOfEnqueuedItems = 0;
  145. public function getNumberOfEnqueuedItems(): int
  146. {
  147. return $this->numberOfEnqueuedItems;
  148. }
  149. #[ORM\Column(
  150. type : Types::INTEGER,
  151. nullable: false
  152. )]
  153. private int $numberOfSuccessfullyProcessedItems = 0;
  154. public function getNumberOfSuccessfullyProcessedItems(): int
  155. {
  156. return $this->numberOfSuccessfullyProcessedItems;
  157. }
  158. #[ORM\Column(
  159. type : Types::INTEGER,
  160. nullable: false
  161. )]
  162. private int $numberOfUnsuccessfullyProcessedItems = 0;
  163. public function getNumberOfUnsuccessfullyProcessedItems(): int
  164. {
  165. return $this->numberOfUnsuccessfullyProcessedItems;
  166. }
  167. #[ORM\Column(
  168. type : Types::DATETIME_MUTABLE,
  169. nullable: true
  170. )]
  171. private ?DateTime $finalizationStartedAt = null;
  172. public function getFinalizationStartedAt(): ?DateTime
  173. {
  174. return $this->finalizationStartedAt;
  175. }
  176. #[ORM\Column(
  177. type: Types::DATETIME_MUTABLE,
  178. nullable: true
  179. )]
  180. private ?DateTime $markedForDeletionAfter = null;
  181. public function getMarkedForDeletionAfter(): ?DateTime
  182. {
  183. return $this->markedForDeletionAfter;
  184. }
  185. public function setMarkedForDeletionAfter(?DateTime $markedForDeletionAfter): void
  186. {
  187. $this->markedForDeletionAfter = $markedForDeletionAfter;
  188. }
  189. }