Add step type, step key, and updated timestamp to run logs

[MAILPOET-5568]
This commit is contained in:
Jan Jakes
2023-09-04 13:06:31 +02:00
committed by Aschepikov
parent c2027932c0
commit 370f4ee3ae
7 changed files with 77 additions and 34 deletions

View File

@@ -5,6 +5,7 @@ namespace MailPoet\Automation\Engine\Control;
use Exception;
use MailPoet\Automation\Engine\Data\Automation;
use MailPoet\Automation\Engine\Data\AutomationRun;
use MailPoet\Automation\Engine\Data\AutomationRunLog;
use MailPoet\Automation\Engine\Data\StepRunArgs;
use MailPoet\Automation\Engine\Data\StepValidationArgs;
use MailPoet\Automation\Engine\Data\SubjectEntry;
@@ -86,7 +87,7 @@ class StepHandler {
return;
}
$logger = $this->stepRunLoggerFactory->createLogger($runId, $stepId);
$logger = $this->stepRunLoggerFactory->createLogger($runId, $stepId, AutomationRunLog::TYPE_ACTION);
$logger->logStart();
try {
$this->handleStep($runId, $stepId, $runNumber);

View File

@@ -25,16 +25,21 @@ class StepRunLogger {
/** @var AutomationRunLog|null */
private $log;
/** @var string */
private $stepType;
public function __construct(
AutomationRunLogStorage $automationRunLogStorage,
Hooks $hooks,
int $runId,
string $stepId
string $stepId,
string $stepType
) {
$this->automationRunLogStorage = $automationRunLogStorage;
$this->hooks = $hooks;
$this->runId = $runId;
$this->stepId = $stepId;
$this->stepType = $stepType;
}
public function logStart(): void {
@@ -44,7 +49,7 @@ class StepRunLogger {
public function logSuccess(): void {
$log = $this->getLog();
$log->setStatus(AutomationRunLog::STATUS_COMPLETE);
$log->setCompletedAt(new DateTimeImmutable());
$log->setUpdatedAt(new DateTimeImmutable());
$this->triggerAfterRunHook($log);
$this->automationRunLogStorage->updateAutomationRunLog($log);
}
@@ -53,7 +58,7 @@ class StepRunLogger {
$log = $this->getLog();
$log->setStatus(AutomationRunLog::STATUS_FAILED);
$log->setError($error);
$log->setCompletedAt(new DateTimeImmutable());
$log->setUpdatedAt(new DateTimeImmutable());
$this->triggerAfterRunHook($log);
$this->automationRunLogStorage->updateAutomationRunLog($log);
}
@@ -64,7 +69,7 @@ class StepRunLogger {
}
if (!$this->log) {
$log = new AutomationRunLog($this->runId, $this->stepId);
$log = new AutomationRunLog($this->runId, $this->stepId, $this->stepType);
$id = $this->automationRunLogStorage->createAutomationRunLog($log);
$this->log = $this->automationRunLogStorage->getAutomationRunLog($id);
}

View File

@@ -20,7 +20,7 @@ class StepRunLoggerFactory {
$this->hooks = $hooks;
}
public function createLogger(int $runId, string $stepId): StepRunLogger {
return new StepRunLogger($this->automationRunLogStorage, $this->hooks, $runId, $stepId);
public function createLogger(int $runId, string $stepId, string $stepType): StepRunLogger {
return new StepRunLogger($this->automationRunLogStorage, $this->hooks, $runId, $stepId, $stepType);
}
}