Clear the in_progress flag if WC sync task fails [MAILPOET-2202]

This commit is contained in:
wxa
2019-07-28 16:43:48 +03:00
committed by M. Shull
parent 8b867a7b4f
commit c4f2be2edf
2 changed files with 21 additions and 1 deletions

View File

@ -49,7 +49,13 @@ class WooCommerceSync extends SimpleWorker {
$task->meta = ['in_progress' => true];
$task->save();
$this->woocommerce_segment->synchronizeCustomers();
try {
$this->woocommerce_segment->synchronizeCustomers();
} catch (\Exception $e) {
$task->meta = null;
$task->save();
throw $e;
}
return true;
}

View File

@ -42,6 +42,20 @@ class WooCommerceSyncTest extends \MailPoetTest {
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() {
$this->woocommerce_segment->expects($this->once())
->method('synchronizeCustomers');