Add run number to logs
[MAILPOET-5568]
This commit is contained in:
@@ -87,11 +87,10 @@ class StepHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
$logger = $this->stepRunLoggerFactory->createLogger($runId, $stepId, AutomationRunLog::TYPE_ACTION);
|
||||
$logger = $this->stepRunLoggerFactory->createLogger($runId, $stepId, AutomationRunLog::TYPE_ACTION, $runNumber);
|
||||
$logger->logStart();
|
||||
try {
|
||||
$this->handleStep($runId, $stepId, $runNumber, $logger);
|
||||
$logger->logSuccess();
|
||||
} catch (Throwable $e) {
|
||||
$status = $e instanceof InvalidStateException && $e->getErrorCode() === 'mailpoet_automation_not_active'
|
||||
? AutomationRun::STATUS_CANCELLED
|
||||
@@ -155,6 +154,13 @@ class StepHandler {
|
||||
if (!$this->stepScheduler->hasScheduledStep($args)) {
|
||||
$this->stepScheduler->scheduleNextStep($args);
|
||||
}
|
||||
|
||||
// logging
|
||||
if ($this->stepScheduler->hasScheduledProgress($args)) {
|
||||
$logger->logProgress();
|
||||
} else {
|
||||
$logger->logSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
/** @return SubjectEntry<Subject<Payload>>[] */
|
||||
|
@@ -29,18 +29,23 @@ class StepRunLogger {
|
||||
/** @var string */
|
||||
private $stepType;
|
||||
|
||||
/** @var int */
|
||||
private $runNumber;
|
||||
|
||||
public function __construct(
|
||||
AutomationRunLogStorage $automationRunLogStorage,
|
||||
Hooks $hooks,
|
||||
int $runId,
|
||||
string $stepId,
|
||||
string $stepType
|
||||
string $stepType,
|
||||
int $runNumber
|
||||
) {
|
||||
$this->automationRunLogStorage = $automationRunLogStorage;
|
||||
$this->hooks = $hooks;
|
||||
$this->runId = $runId;
|
||||
$this->stepId = $stepId;
|
||||
$this->stepType = $stepType;
|
||||
$this->runNumber = $runNumber;
|
||||
}
|
||||
|
||||
public function logStart(): void {
|
||||
@@ -53,6 +58,13 @@ class StepRunLogger {
|
||||
$this->automationRunLogStorage->updateAutomationRunLog($log);
|
||||
}
|
||||
|
||||
public function logProgress(): void {
|
||||
$log = $this->getLog();
|
||||
$log->setStatus(AutomationRunLog::STATUS_RUNNING);
|
||||
$log->setUpdatedAt(new DateTimeImmutable());
|
||||
$this->automationRunLogStorage->updateAutomationRunLog($log);
|
||||
}
|
||||
|
||||
public function logSuccess(): void {
|
||||
$log = $this->getLog();
|
||||
$log->setStatus(AutomationRunLog::STATUS_COMPLETE);
|
||||
@@ -77,6 +89,7 @@ class StepRunLogger {
|
||||
|
||||
if (!$this->log) {
|
||||
$log = new AutomationRunLog($this->runId, $this->stepId, $this->stepType);
|
||||
$log->setRunNumber($this->runNumber);
|
||||
$id = $this->automationRunLogStorage->createAutomationRunLog($log);
|
||||
$this->log = $this->automationRunLogStorage->getAutomationRunLog($id);
|
||||
}
|
||||
@@ -84,6 +97,8 @@ class StepRunLogger {
|
||||
if (!$this->log) {
|
||||
throw new InvalidStateException('Failed to create automation run log');
|
||||
}
|
||||
|
||||
$this->log->setRunNumber($this->runNumber);
|
||||
return $this->log;
|
||||
}
|
||||
|
||||
|
@@ -20,7 +20,7 @@ class StepRunLoggerFactory {
|
||||
$this->hooks = $hooks;
|
||||
}
|
||||
|
||||
public function createLogger(int $runId, string $stepId, string $stepType): StepRunLogger {
|
||||
return new StepRunLogger($this->automationRunLogStorage, $this->hooks, $runId, $stepId, $stepType);
|
||||
public function createLogger(int $runId, string $stepId, string $stepType, int $runNumber): StepRunLogger {
|
||||
return new StepRunLogger($this->automationRunLogStorage, $this->hooks, $runId, $stepId, $stepType, $runNumber);
|
||||
}
|
||||
}
|
||||
|
@@ -101,7 +101,7 @@ class TriggerHandler {
|
||||
$automationRun->setId($automationRunId);
|
||||
$this->stepScheduler->scheduleNextStep($stepRunArgs);
|
||||
|
||||
$logger = $this->stepRunLoggerFactory->createLogger($automationRunId, $step->getId(), AutomationRunLog::TYPE_TRIGGER);
|
||||
$logger = $this->stepRunLoggerFactory->createLogger($automationRunId, $step->getId(), AutomationRunLog::TYPE_TRIGGER, 1);
|
||||
$logger->logStepData($step);
|
||||
$logger->logSuccess();
|
||||
}
|
||||
|
@@ -47,6 +47,9 @@ class AutomationRunLog {
|
||||
/** @var DateTimeImmutable */
|
||||
private $updatedAt;
|
||||
|
||||
/** @var int */
|
||||
private $runNumber = 1;
|
||||
|
||||
/** @var array */
|
||||
private $data = [];
|
||||
|
||||
@@ -119,6 +122,14 @@ class AutomationRunLog {
|
||||
return $this->updatedAt;
|
||||
}
|
||||
|
||||
public function getRunNumber(): int {
|
||||
return $this->runNumber;
|
||||
}
|
||||
|
||||
public function setRunNumber(int $runNumber): void {
|
||||
$this->runNumber = $runNumber;
|
||||
}
|
||||
|
||||
public function setUpdatedAt(DateTimeImmutable $updatedAt): void {
|
||||
$this->updatedAt = $updatedAt;
|
||||
}
|
||||
@@ -150,6 +161,7 @@ class AutomationRunLog {
|
||||
'status' => $this->status,
|
||||
'started_at' => $this->startedAt->format(DateTimeImmutable::W3C),
|
||||
'updated_at' => $this->updatedAt->format(DateTimeImmutable::W3C),
|
||||
'run_number' => $this->runNumber,
|
||||
'data' => Json::encode($this->data),
|
||||
'error' => Json::encode($this->error),
|
||||
];
|
||||
@@ -172,6 +184,7 @@ class AutomationRunLog {
|
||||
$log->status = $data['status'];
|
||||
$log->startedAt = new DateTimeImmutable($data['started_at']);
|
||||
$log->updatedAt = new DateTimeImmutable($data['updated_at']);
|
||||
$log->runNumber = (int)$data['run_number'];
|
||||
$log->data = Json::decode($data['data']);
|
||||
$log->error = Json::decode($data['error']);
|
||||
return $log;
|
||||
|
Reference in New Issue
Block a user