Use processTaskStrategy() instead of custom logic in Migration worker
[MAILPOET-2538]
This commit is contained in:
committed by
Jack Kitterhing
parent
8a8b34e554
commit
ac794aaca2
@ -21,7 +21,7 @@ class Migration extends SimpleWorker {
|
|||||||
return empty($completed_tasks);
|
return empty($completed_tasks);
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareTask(ScheduledTask $task) {
|
function prepareTaskStrategy(ScheduledTask $task) {
|
||||||
$unmigrated_columns = $this->checkUnmigratedColumnsExist();
|
$unmigrated_columns = $this->checkUnmigratedColumnsExist();
|
||||||
$unmigrated_queues_count = 0;
|
$unmigrated_queues_count = 0;
|
||||||
$unmigrated_queue_subscribers = [];
|
$unmigrated_queue_subscribers = [];
|
||||||
@ -43,8 +43,7 @@ class Migration extends SimpleWorker {
|
|||||||
|
|
||||||
// pause sending while the migration is in process
|
// pause sending while the migration is in process
|
||||||
$this->pauseSending();
|
$this->pauseSending();
|
||||||
|
return true;
|
||||||
return parent::prepareTask($task);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function pauseSending() {
|
function pauseSending() {
|
||||||
@ -74,13 +73,10 @@ class Migration extends SimpleWorker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function processTask(ScheduledTask $task) {
|
function processTaskStrategy(ScheduledTask $task) {
|
||||||
$this->migrateSendingQueues();
|
$this->migrateSendingQueues();
|
||||||
$this->migrateSubscribers();
|
$this->migrateSubscribers();
|
||||||
|
|
||||||
$this->complete($task);
|
|
||||||
$this->resumeSending();
|
$this->resumeSending();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,13 +93,14 @@ abstract class SimpleWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function prepareTask(ScheduledTask $task) {
|
function prepareTask(ScheduledTask $task) {
|
||||||
$task->status = null;
|
|
||||||
$task->save();
|
|
||||||
|
|
||||||
// abort if execution limit is reached
|
// abort if execution limit is reached
|
||||||
$this->cron_helper->enforceExecutionLimit($this->timer);
|
$this->cron_helper->enforceExecutionLimit($this->timer);
|
||||||
|
|
||||||
return true;
|
$prepare_completed = $this->prepareTaskStrategy($task);
|
||||||
|
if ($prepare_completed) {
|
||||||
|
$task->status = null;
|
||||||
|
$task->save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function processTask(ScheduledTask $task) {
|
function processTask(ScheduledTask $task) {
|
||||||
@ -133,6 +134,10 @@ abstract class SimpleWorker {
|
|||||||
return (bool)$completed;
|
return (bool)$completed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function prepareTaskStrategy(ScheduledTask $task) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function processTaskStrategy(ScheduledTask $task) {
|
function processTaskStrategy(ScheduledTask $task) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,9 @@ use MailPoet\Tasks\Sending as SendingTask;
|
|||||||
use MailPoet\WP\Functions as WPFunctions;
|
use MailPoet\WP\Functions as WPFunctions;
|
||||||
|
|
||||||
class MigrationTest extends \MailPoetTest {
|
class MigrationTest extends \MailPoetTest {
|
||||||
|
/** @var Migration */
|
||||||
|
private $worker;
|
||||||
|
|
||||||
function _before() {
|
function _before() {
|
||||||
parent::_before();
|
parent::_before();
|
||||||
// Alter table to test migration
|
// Alter table to test migration
|
||||||
@ -63,17 +66,15 @@ class MigrationTest extends \MailPoetTest {
|
|||||||
$this->worker->pauseSending();
|
$this->worker->pauseSending();
|
||||||
expect(MailerLog::isSendingPaused())->true();
|
expect(MailerLog::isSendingPaused())->true();
|
||||||
$task = $this->createScheduledTask();
|
$task = $this->createScheduledTask();
|
||||||
$result = $this->worker->prepareTask($task);
|
$this->worker->prepareTask($task);
|
||||||
expect($result)->false();
|
|
||||||
expect(MailerLog::isSendingPaused())->false();
|
expect(MailerLog::isSendingPaused())->false();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItCompletesTaskIfThereIsNothingToMigrate() {
|
function testItCompletesTaskIfThereIsNothingToMigrate() {
|
||||||
SendingQueue::deleteMany();
|
SendingQueue::deleteMany();
|
||||||
$task = $this->createScheduledTask();
|
$task = $this->createScheduledTask();
|
||||||
$result = $this->worker->prepareTask($task);
|
$this->worker->prepareTask($task);
|
||||||
expect(ScheduledTask::findOne($task->id)->status)->equals(ScheduledTask::STATUS_COMPLETED);
|
expect(ScheduledTask::findOne($task->id)->status)->equals(ScheduledTask::STATUS_COMPLETED);
|
||||||
expect($result)->false();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItMigratesSendingQueuesAndSubscribers() {
|
function testItMigratesSendingQueuesAndSubscribers() {
|
||||||
|
Reference in New Issue
Block a user