Log step key data

[MAILPOET-5568]
This commit is contained in:
Jan Jakes
2023-09-04 13:12:58 +02:00
committed by Aschepikov
parent 370f4ee3ae
commit a13dc71cd0
2 changed files with 11 additions and 2 deletions

View File

@ -90,7 +90,7 @@ class StepHandler {
$logger = $this->stepRunLoggerFactory->createLogger($runId, $stepId, AutomationRunLog::TYPE_ACTION);
$logger->logStart();
try {
$this->handleStep($runId, $stepId, $runNumber);
$this->handleStep($runId, $stepId, $runNumber, $logger);
$logger->logSuccess();
} catch (Throwable $e) {
$status = $e instanceof InvalidStateException && $e->getErrorCode() === 'mailpoet_automation_not_active'
@ -110,7 +110,7 @@ class StepHandler {
}
}
private function handleStep(int $runId, string $stepId, int $runNumber): void {
private function handleStep(int $runId, string $stepId, int $runNumber, StepRunLogger $logger): void {
$automationRun = $this->automationRunStorage->getAutomationRun($runId);
if (!$automationRun) {
throw Exceptions::automationRunNotFound($runId);
@ -134,6 +134,8 @@ class StepHandler {
throw Exceptions::automationStepNotFound($stepId);
}
$logger->logStepData($stepData);
$step = $this->registry->getStep($stepData->getKey());
if (!$step instanceof Action) {
throw new InvalidStateException();

View File

@ -4,6 +4,7 @@ namespace MailPoet\Automation\Engine\Control;
use DateTimeImmutable;
use MailPoet\Automation\Engine\Data\AutomationRunLog;
use MailPoet\Automation\Engine\Data\Step;
use MailPoet\Automation\Engine\Hooks;
use MailPoet\Automation\Engine\Storage\AutomationRunLogStorage;
use MailPoet\InvalidStateException;
@ -46,6 +47,12 @@ class StepRunLogger {
$this->getLog();
}
public function logStepData(Step $step): void {
$log = $this->getLog();
$log->setStepKey($step->getKey());
$this->automationRunLogStorage->updateAutomationRunLog($log);
}
public function logSuccess(): void {
$log = $this->getLog();
$log->setStatus(AutomationRunLog::STATUS_COMPLETE);