Add method for getting running sending tasks
[MAILPOET-4366]
This commit is contained in:
@ -6,6 +6,7 @@ use DateTimeInterface;
|
||||
use MailPoet\Doctrine\EntityTraits\AutoincrementedIdTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\CreatedAtTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\DeletedAtTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\SafeToOneAssociationLoadTrait;
|
||||
use MailPoet\Doctrine\EntityTraits\UpdatedAtTrait;
|
||||
use MailPoetVendor\Doctrine\Common\Collections\ArrayCollection;
|
||||
use MailPoetVendor\Doctrine\Common\Collections\Collection;
|
||||
@ -32,6 +33,7 @@ class ScheduledTaskEntity {
|
||||
use CreatedAtTrait;
|
||||
use UpdatedAtTrait;
|
||||
use DeletedAtTrait;
|
||||
use SafeToOneAssociationLoadTrait;
|
||||
|
||||
/**
|
||||
* @ORM\Column(type="string", nullable=true)
|
||||
@ -87,6 +89,12 @@ class ScheduledTaskEntity {
|
||||
*/
|
||||
public $subscribers;
|
||||
|
||||
/**
|
||||
* @ORM\OneToOne(targetEntity="MailPoet\Entities\SendingQueueEntity", mappedBy="task", fetch="EAGER")
|
||||
* @var SendingQueueEntity|null
|
||||
*/
|
||||
private $sendingQueue;
|
||||
|
||||
public function __construct() {
|
||||
$this->subscribers = new ArrayCollection();
|
||||
}
|
||||
@ -203,4 +211,13 @@ class ScheduledTaskEntity {
|
||||
public function getSubscribers(): Collection {
|
||||
return $this->subscribers;
|
||||
}
|
||||
|
||||
public function getSendingQueue(): ?SendingQueueEntity {
|
||||
$this->safelyLoadToOneAssociation('sendingQueue');
|
||||
return $this->sendingQueue;
|
||||
}
|
||||
|
||||
public function setSendingQueue(SendingQueueEntity $sendingQueue): void {
|
||||
$this->sendingQueue = $sendingQueue;
|
||||
}
|
||||
}
|
||||
|
@ -125,6 +125,25 @@ class ScheduledTasksRepository extends Repository {
|
||||
return $this->findByTypeAndStatus($type, ScheduledTaskEntity::STATUS_SCHEDULED, $limit, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ScheduledTaskEntity[]
|
||||
*/
|
||||
public function findRunningSendingTasks(?int $limit = null): array {
|
||||
return $this->doctrineRepository->createQueryBuilder('st')
|
||||
->select('st')
|
||||
->join('st.sendingQueue', 'sq')
|
||||
->where('st.type = :type')
|
||||
->andWhere('st.status IS NULL')
|
||||
->andWhere('st.deletedAt IS NULL')
|
||||
->andWhere('sq.deletedAt IS NULL')
|
||||
->orderBy('st.priority', 'ASC')
|
||||
->addOrderBy('st.updatedAt', 'ASC')
|
||||
->setMaxResults($limit)
|
||||
->setParameter('type', ScheduledTaskEntity::TYPE_SENDING)
|
||||
->getQuery()
|
||||
->getResult();
|
||||
}
|
||||
|
||||
protected function findByTypeAndStatus($type, $status, $limit = null, $future = false) {
|
||||
$queryBuilder = $this->doctrineRepository->createQueryBuilder('st')
|
||||
->select('st')
|
||||
|
Reference in New Issue
Block a user