Clear the in_progress flag if WC sync task fails [MAILPOET-2202]
This commit is contained in:
@ -49,7 +49,13 @@ class WooCommerceSync extends SimpleWorker {
|
|||||||
$task->meta = ['in_progress' => true];
|
$task->meta = ['in_progress' => true];
|
||||||
$task->save();
|
$task->save();
|
||||||
|
|
||||||
$this->woocommerce_segment->synchronizeCustomers();
|
try {
|
||||||
|
$this->woocommerce_segment->synchronizeCustomers();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$task->meta = null;
|
||||||
|
$task->save();
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,20 @@ class WooCommerceSyncTest extends \MailPoetTest {
|
|||||||
expect($task->getMeta())->notEmpty();
|
expect($task->getMeta())->notEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testItWillResetTheInProgressFlagOnFail() {
|
||||||
|
$task = $this->createScheduledTask();
|
||||||
|
$this->woocommerce_segment->expects($this->once())
|
||||||
|
->method('synchronizeCustomers')
|
||||||
|
->willThrowException(new \Exception('test error'));
|
||||||
|
try {
|
||||||
|
$this->worker->processTaskStrategy($task);
|
||||||
|
$this->fail('An exception should be thrown');
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
expect($e->getMessage())->equals('test error');
|
||||||
|
expect($task->getMeta())->isEmpty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function testItWillRescheduleTaskIfItIsRunningForTooLong() {
|
function testItWillRescheduleTaskIfItIsRunningForTooLong() {
|
||||||
$this->woocommerce_segment->expects($this->once())
|
$this->woocommerce_segment->expects($this->once())
|
||||||
->method('synchronizeCustomers');
|
->method('synchronizeCustomers');
|
||||||
|
Reference in New Issue
Block a user