Move task type const from entity to worker

[MAILPOET-4366]
This commit is contained in:
Jan Lysý
2022-08-10 13:32:33 +02:00
committed by Veljko V
parent 77eaa7e710
commit 5dfda9f3e2
4 changed files with 10 additions and 7 deletions

View File

@ -32,6 +32,8 @@ use MailPoetVendor\Carbon\Carbon;
class SendingQueue { class SendingQueue {
public $mailerTask; public $mailerTask;
public $newsletterTask; public $newsletterTask;
const TASK_TYPE = 'sending';
const TASK_BATCH_SIZE = 5; const TASK_BATCH_SIZE = 5;
const EMAIL_WITH_INVALID_SEGMENT_OPTION = 'mailpoet_email_with_invalid_segment'; const EMAIL_WITH_INVALID_SEGMENT_OPTION = 'mailpoet_email_with_invalid_segment';

View File

@ -22,7 +22,6 @@ class ScheduledTaskEntity {
const STATUS_PAUSED = 'paused'; const STATUS_PAUSED = 'paused';
const STATUS_INVALID = 'invalid'; const STATUS_INVALID = 'invalid';
const VIRTUAL_STATUS_RUNNING = 'running'; // For historical reasons this is stored as null in DB const VIRTUAL_STATUS_RUNNING = 'running'; // For historical reasons this is stored as null in DB
const TYPE_SENDING = 'sending';
const PRIORITY_HIGH = 1; const PRIORITY_HIGH = 1;
const PRIORITY_MEDIUM = 5; const PRIORITY_MEDIUM = 5;
const PRIORITY_LOW = 10; const PRIORITY_LOW = 10;

View File

@ -2,6 +2,7 @@
namespace MailPoet\Newsletter\Sending; namespace MailPoet\Newsletter\Sending;
use MailPoet\Cron\Workers\SendingQueue\SendingQueue;
use MailPoet\Doctrine\Repository; use MailPoet\Doctrine\Repository;
use MailPoet\Entities\NewsletterEntity; use MailPoet\Entities\NewsletterEntity;
use MailPoet\Entities\ScheduledTaskEntity; use MailPoet\Entities\ScheduledTaskEntity;
@ -138,7 +139,7 @@ class ScheduledTasksRepository extends Repository {
->orderBy('st.priority', 'ASC') ->orderBy('st.priority', 'ASC')
->addOrderBy('st.updatedAt', 'ASC') ->addOrderBy('st.updatedAt', 'ASC')
->setMaxResults($limit) ->setMaxResults($limit)
->setParameter('type', ScheduledTaskEntity::TYPE_SENDING) ->setParameter('type', SendingQueue::TASK_TYPE)
->getQuery() ->getQuery()
->getResult(); ->getResult();
} }

View File

@ -2,6 +2,7 @@
namespace MailPoet\Newsletter\Sending; namespace MailPoet\Newsletter\Sending;
use MailPoet\Cron\Workers\SendingQueue\SendingQueue as SendingQueueWorker;
use MailPoet\Entities\ScheduledTaskEntity; use MailPoet\Entities\ScheduledTaskEntity;
use MailPoet\Test\DataFactories\ScheduledTask as ScheduledTaskFactory; use MailPoet\Test\DataFactories\ScheduledTask as ScheduledTaskFactory;
use MailPoet\Test\DataFactories\SendingQueue; use MailPoet\Test\DataFactories\SendingQueue;
@ -70,19 +71,19 @@ class ScheduledTasksRepositoryTest extends \MailPoetTest {
public function testItCanGetRunningSendingTasks(): void { public function testItCanGetRunningSendingTasks(): void {
// running task // running task
$task = $this->scheduledTaskFactory->create(ScheduledTaskEntity::TYPE_SENDING, null, Carbon::now()->subDay()); $task = $this->scheduledTaskFactory->create(SendingQueueWorker::TASK_TYPE, null, Carbon::now()->subDay());
$this->sendingQueueFactory->create($task); $this->sendingQueueFactory->create($task);
$expectedResult[] = $task; $expectedResult[] = $task;
// deleted task // deleted task
$task = $this->scheduledTaskFactory->create(ScheduledTaskEntity::TYPE_SENDING, null, Carbon::now()->subDay(), Carbon::now()); $task = $this->scheduledTaskFactory->create(SendingQueueWorker::TASK_TYPE, null, Carbon::now()->subDay(), Carbon::now());
$this->sendingQueueFactory->create($task); $this->sendingQueueFactory->create($task);
// without sending queue // without sending queue
$this->scheduledTaskFactory->create(ScheduledTaskEntity::TYPE_SENDING, null, Carbon::now()->subDay()); $this->scheduledTaskFactory->create(SendingQueueWorker::TASK_TYPE, null, Carbon::now()->subDay());
// scheduled in future // scheduled in future
$task = $this->scheduledTaskFactory->create(ScheduledTaskEntity::TYPE_SENDING, ScheduledTaskEntity::STATUS_COMPLETED, Carbon::now()->addDay()); $task = $this->scheduledTaskFactory->create(SendingQueueWorker::TASK_TYPE, ScheduledTaskEntity::STATUS_COMPLETED, Carbon::now()->addDay());
$this->sendingQueueFactory->create($task); $this->sendingQueueFactory->create($task);
// wrong status // wrong status
$task = $this->scheduledTaskFactory->create(ScheduledTaskEntity::TYPE_SENDING, ScheduledTaskEntity::STATUS_SCHEDULED, Carbon::now()->subDay()); $task = $this->scheduledTaskFactory->create(SendingQueueWorker::TASK_TYPE, ScheduledTaskEntity::STATUS_SCHEDULED, Carbon::now()->subDay());
$this->sendingQueueFactory->create($task); $this->sendingQueueFactory->create($task);
$tasks = $this->repository->findRunningSendingTasks(); $tasks = $this->repository->findRunningSendingTasks();