diff --git a/application/Espo/Core/Job/QueueProcessor.php b/application/Espo/Core/Job/QueueProcessor.php index 4fbbc722c4..ec707a04ce 100644 --- a/application/Espo/Core/Job/QueueProcessor.php +++ b/application/Espo/Core/Job/QueueProcessor.php @@ -32,7 +32,6 @@ namespace Espo\Core\Job; use Espo\Entities\Job as JobEntity; use Espo\Core\Job\QueueProcessor\Params; use Espo\Core\ORM\EntityManager; -use Espo\Core\Utils\DateTime as DateTimeUtil; use Espo\Core\Utils\System; use Espo\Core\Job\Job\Status; @@ -114,14 +113,14 @@ class QueueProcessor return; } - $job->set('startedAt', date(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT)); + $job->setStartedAtNow(); if ($useProcessPool) { - $job->set('status', Status::READY); + $job->setStatus(Status::READY); } else { - $job->set('status', Status::RUNNING); - $job->set('pid', System::getPid()); + $job->setStatus(Status::RUNNING); + $job->setPid(System::getPid()); } $this->entityManager->saveEntity($job); diff --git a/application/Espo/Entities/Job.php b/application/Espo/Entities/Job.php index 3913565b0a..d9f2f13ba2 100644 --- a/application/Espo/Entities/Job.php +++ b/application/Espo/Entities/Job.php @@ -29,7 +29,10 @@ namespace Espo\Entities; +use Espo\Core\Job\Job\Status; use Espo\Core\ORM\Entity; +use Espo\Core\Utils\DateTime as DateTimeUtil; + use stdClass; class Job extends Entity @@ -171,4 +174,36 @@ class Job extends Entity { return $this->get('failedAttempts') ?? 0; } + + /** + * Set status. + * + * @param Status::* $status + */ + public function setStatus(string $status): self + { + $this->set('status', $status); + + return $this; + } + + /** + * Set PID. + */ + public function setPid(?int $pid): self + { + $this->set('pid', $pid); + + return $this; + } + + /** + * Set started-at to now. + */ + public function setStartedAtNow(): self + { + $this->set('startedAt', date(DateTimeUtil::SYSTEM_DATE_TIME_FORMAT)); + + return $this; + } }