From 2c2f15a5628a9f70e20fc3d6743c5ad9bd4f118f Mon Sep 17 00:00:00 2001 From: John Oleksowicz Date: Mon, 12 Sep 2022 12:49:13 -0500 Subject: [PATCH] Use completedAt timestamp for success and failures [MAILPOET-4463] --- .../Automation/Engine/Control/StepHandler.php | 4 ++-- .../Automation/Engine/Data/WorkflowRunLog.php | 3 ++- .../Engine/Data/WorkflowRunLogTest.php | 18 +++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mailpoet/lib/Automation/Engine/Control/StepHandler.php b/mailpoet/lib/Automation/Engine/Control/StepHandler.php index 591e16cc23..550f7c5fb1 100644 --- a/mailpoet/lib/Automation/Engine/Control/StepHandler.php +++ b/mailpoet/lib/Automation/Engine/Control/StepHandler.php @@ -123,8 +123,8 @@ class StepHandler { $log = new WorkflowRunLog($workflowRun->getId(), $step->getId(), $args); try { $this->stepRunners[$stepType]->run($step, $workflow, $workflowRun); - $log->markCompleted(); - } catch (Exception $e) { + $log->markCompletedSuccessfully(); + } catch (\Exception $e) { $log->markFailed(); $log->addError($e); throw $e; diff --git a/mailpoet/lib/Automation/Engine/Data/WorkflowRunLog.php b/mailpoet/lib/Automation/Engine/Data/WorkflowRunLog.php index 357afcb3f9..fb2f5dfb7e 100644 --- a/mailpoet/lib/Automation/Engine/Data/WorkflowRunLog.php +++ b/mailpoet/lib/Automation/Engine/Data/WorkflowRunLog.php @@ -121,13 +121,14 @@ class WorkflowRunLog { ]; } - public function markCompleted(): void { + public function markCompletedSuccessfully(): void { $this->status = self::STATUS_COMPLETED; $this->completedAt = new DateTimeImmutable(); } public function markFailed(): void { $this->status = self::STATUS_FAILED; + $this->completedAt = new DateTimeImmutable(); } public function addError(\Exception $exception, string $userFacingMessage = ''): void { diff --git a/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php b/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php index bb106d48dd..8514350030 100644 --- a/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Data/WorkflowRunLogTest.php @@ -115,6 +115,15 @@ class WorkflowRunLogTest extends \MailPoetTest { expect($log->getCompletedAt())->isInstanceOf(\DateTimeImmutable::class); } + public function testItAddsCompletedAtTimestampAfterFailing(): void { + $workflowRunLogs = $this->getLogsForAction(function() { + throw new \Exception('error'); + }); + expect($workflowRunLogs)->count(1); + $log = $workflowRunLogs[0]; + expect($log->getCompletedAt())->isInstanceOf(\DateTimeImmutable::class); + } + public function testItLogsFailedStatusCorrectly(): void { $workflowRunLogs = $this->getLogsForAction(function() { throw new \Exception('error'); @@ -124,15 +133,6 @@ class WorkflowRunLogTest extends \MailPoetTest { expect($log->getStatus())->equals('failed'); } - public function testItDoesNotHaveCompletedAtIfItFailsToRun(): void { - $workflowRunLogs = $this->getLogsForAction(function() { - throw new \Exception('error'); - }); - expect($workflowRunLogs)->count(1); - $log = $workflowRunLogs[0]; - expect($log->getCompletedAt())->null(); - } - public function testItIncludesErrorOnFailure(): void { $workflowRunLogs = $this->getLogsForAction(function() { throw new \Exception('error', 12345);