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