Store the 'in_progress' flag for workers in a separate column [MAILPOET-2443]
This commit is contained in:
@ -129,6 +129,7 @@ class Migrator {
|
||||
'created_at timestamp NULL,', // must be NULL, see comment at the top
|
||||
'updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,',
|
||||
'deleted_at timestamp NULL,',
|
||||
'in_progress int(1),',
|
||||
'reschedule_count int(11) NOT NULL DEFAULT 0,',
|
||||
'meta longtext,',
|
||||
'PRIMARY KEY (id),',
|
||||
|
@ -150,8 +150,7 @@ abstract class SimpleWorker {
|
||||
}
|
||||
|
||||
private function isInProgress(ScheduledTask $task) {
|
||||
$meta = $task->getMeta();
|
||||
if (!empty($meta['in_progress'])) {
|
||||
if (!empty($task->in_progress)) {
|
||||
// Do not run multiple instances of the task
|
||||
return true;
|
||||
}
|
||||
@ -159,12 +158,12 @@ abstract class SimpleWorker {
|
||||
}
|
||||
|
||||
private function startProgress(ScheduledTask $task) {
|
||||
$task->meta = array_merge($task->getMeta(), ['in_progress' => true]);
|
||||
$task->in_progress = true;
|
||||
$task->save();
|
||||
}
|
||||
|
||||
private function stopProgress(ScheduledTask $task) {
|
||||
$task->meta = array_merge($task->getMeta(), ['in_progress' => null]);
|
||||
$task->in_progress = false;
|
||||
$task->save();
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ use MailPoet\WP\Functions as WPFunctions;
|
||||
* @property string|null $type
|
||||
* @property int $priority
|
||||
* @property string|null $scheduled_at
|
||||
* @property boolean|null $in_progress
|
||||
* @property int $reschedule_count
|
||||
* @property string|array|null $meta
|
||||
*/
|
||||
|
@ -214,9 +214,9 @@ class SimpleWorkerTest extends \MailPoetTest {
|
||||
->method('processTaskStrategy')
|
||||
->willReturn(true);
|
||||
$task = $this->createRunningTask();
|
||||
expect(empty($task->getMeta()['in_progress']))->equals(true);
|
||||
expect(empty($task->in_progress))->equals(true);
|
||||
expect($worker->processTask($task))->equals(true);
|
||||
$task->meta = ['in_progress' => true];
|
||||
$task->in_progress = true;
|
||||
expect($worker->processTask($task))->equals(false);
|
||||
}
|
||||
|
||||
@ -233,7 +233,7 @@ class SimpleWorkerTest extends \MailPoetTest {
|
||||
$this->fail('An exception should be thrown');
|
||||
} catch (\Exception $e) {
|
||||
expect($e->getMessage())->equals('test error');
|
||||
expect(empty($task->getMeta()['in_progress']))->equals(true);
|
||||
expect(empty($task->in_progress))->equals(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -254,7 +254,7 @@ class SimpleWorkerTest extends \MailPoetTest {
|
||||
$task = ScheduledTask::findOne($task->id);
|
||||
expect($scheduled_at < $task->scheduled_at)->true();
|
||||
expect($task->status)->equals(ScheduledTask::STATUS_SCHEDULED);
|
||||
expect(empty($task->getMeta()['in_progress']))->equals(true);
|
||||
expect(empty($task->in_progress))->equals(true);
|
||||
}
|
||||
|
||||
function testItCalculatesNextRunDateWithinNextWeekBoundaries() {
|
||||
|
Reference in New Issue
Block a user