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