Use completedAt timestamp for success and failures
[MAILPOET-4463]
This commit is contained in:
committed by
Jan Jakeš
parent
57cf547a8a
commit
2c2f15a562
@ -123,8 +123,8 @@ class StepHandler {
|
|||||||
$log = new WorkflowRunLog($workflowRun->getId(), $step->getId(), $args);
|
$log = new WorkflowRunLog($workflowRun->getId(), $step->getId(), $args);
|
||||||
try {
|
try {
|
||||||
$this->stepRunners[$stepType]->run($step, $workflow, $workflowRun);
|
$this->stepRunners[$stepType]->run($step, $workflow, $workflowRun);
|
||||||
$log->markCompleted();
|
$log->markCompletedSuccessfully();
|
||||||
} catch (Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$log->markFailed();
|
$log->markFailed();
|
||||||
$log->addError($e);
|
$log->addError($e);
|
||||||
throw $e;
|
throw $e;
|
||||||
|
@ -121,13 +121,14 @@ class WorkflowRunLog {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markCompleted(): void {
|
public function markCompletedSuccessfully(): void {
|
||||||
$this->status = self::STATUS_COMPLETED;
|
$this->status = self::STATUS_COMPLETED;
|
||||||
$this->completedAt = new DateTimeImmutable();
|
$this->completedAt = new DateTimeImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function markFailed(): void {
|
public function markFailed(): void {
|
||||||
$this->status = self::STATUS_FAILED;
|
$this->status = self::STATUS_FAILED;
|
||||||
|
$this->completedAt = new DateTimeImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addError(\Exception $exception, string $userFacingMessage = ''): void {
|
public function addError(\Exception $exception, string $userFacingMessage = ''): void {
|
||||||
|
@ -115,6 +115,15 @@ class WorkflowRunLogTest extends \MailPoetTest {
|
|||||||
expect($log->getCompletedAt())->isInstanceOf(\DateTimeImmutable::class);
|
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 {
|
public function testItLogsFailedStatusCorrectly(): void {
|
||||||
$workflowRunLogs = $this->getLogsForAction(function() {
|
$workflowRunLogs = $this->getLogsForAction(function() {
|
||||||
throw new \Exception('error');
|
throw new \Exception('error');
|
||||||
@ -124,15 +133,6 @@ class WorkflowRunLogTest extends \MailPoetTest {
|
|||||||
expect($log->getStatus())->equals('failed');
|
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 {
|
public function testItIncludesErrorOnFailure(): void {
|
||||||
$workflowRunLogs = $this->getLogsForAction(function() {
|
$workflowRunLogs = $this->getLogsForAction(function() {
|
||||||
throw new \Exception('error', 12345);
|
throw new \Exception('error', 12345);
|
||||||
|
Reference in New Issue
Block a user