Remove redundant step args from log

[MAILPOET-4463]
This commit is contained in:
John Oleksowicz
2022-09-13 12:06:20 -05:00
committed by Jan Jakeš
parent d0f8d0f2bb
commit c828b7245d
5 changed files with 6 additions and 24 deletions

View File

@@ -120,7 +120,7 @@ class StepHandler {
$stepType = $step->getType();
if (isset($this->stepRunners[$stepType])) {
$log = new WorkflowRunLog($workflowRun->getId(), $step->getId(), $args);
$log = new WorkflowRunLog($workflowRun->getId(), $step->getId());
try {
$this->stepRunners[$stepType]->run($step, $workflow, $workflowRun);
$log->markCompletedSuccessfully();

View File

@@ -39,18 +39,13 @@ class WorkflowRunLog {
/** @var string */
private $stepId;
/** @var array */
private $args;
public function __construct(
int $workflowRunId,
string $stepId,
array $args,
int $id = null
) {
$this->workflowRunId = $workflowRunId;
$this->stepId = $stepId;
$this->args = $args;
$this->status = self::STATUS_RUNNING;
if ($id) {
@@ -79,10 +74,6 @@ class WorkflowRunLog {
return $this->status;
}
public function getArgs(): array {
return $this->args;
}
public function getError(): array {
return $this->error;
}
@@ -126,7 +117,6 @@ class WorkflowRunLog {
'status' => $this->status,
'started_at' => $this->startedAt->format(DateTimeImmutable::W3C),
'completed_at' => $this->completedAt ? $this->completedAt->format(DateTimeImmutable::W3C) : null,
'args' => Json::encode($this->args),
'error' => Json::encode($this->error),
'data' => Json::encode($this->data),
];
@@ -154,12 +144,11 @@ class WorkflowRunLog {
}
public static function fromArray(array $data): self {
$workflowRunLog = new WorkflowRunLog((int)$data['workflow_run_id'], $data['step_id'], []);
$workflowRunLog = new WorkflowRunLog((int)$data['workflow_run_id'], $data['step_id']);
$workflowRunLog->id = (int)$data['id'];
$workflowRunLog->status = $data['status'];
$workflowRunLog->error = Json::decode($data['error']);
$workflowRunLog->data = Json::decode($data['data']);
$workflowRunLog->args = Json::decode($data['args']);
$workflowRunLog->startedAt = new DateTimeImmutable($data['started_at']);
if ($data['completed_at']) {

View File

@@ -70,7 +70,6 @@ class Migrator {
status varchar(255) NOT NULL,
started_at timestamp NOT NULL,
completed_at timestamp NULL DEFAULT NULL,
args longtext,
error longtext,
data longtext,
PRIMARY KEY (id),

View File

@@ -50,7 +50,7 @@ class WorkflowRunLogTest extends \MailPoetTest {
}
public function testItAllowsSettingData(): void {
$log = new WorkflowRunLog(1, 'step-id', []);
$log = new WorkflowRunLog(1, 'step-id');
$this->assertSame([], $log->getData());
$log->setData('key', 'value');
$data = $log->getData();
@@ -59,7 +59,7 @@ class WorkflowRunLogTest extends \MailPoetTest {
}
public function testItDoesNotAllowSettingDataThatCannotBeSaved(): void {
$log = new WorkflowRunLog(1, 'step-id', []);
$log = new WorkflowRunLog(1, 'step-id');
$badData = [
function() { echo 'closures cannot be serialized'; }
];
@@ -157,12 +157,6 @@ class WorkflowRunLogTest extends \MailPoetTest {
expect(count($error['trace']))->greaterThan(0);
}
public function testItLogsStepArgs(): void {
$log = $this->getLogsForAction()[0];
expect($log->getArgs())->count(2);
expect(array_keys($log->getArgs()))->equals(['workflow_run_id', 'step_id']);
}
public function _after() {
global $wpdb;
$sql = 'truncate ' . $wpdb->prefix . 'mailpoet_workflow_run_logs';

View File

@@ -15,7 +15,7 @@ class WorkflowRunLogStorageTest extends \MailPoetTest {
}
public function testItSavesAndRetrievesAsExpected() {
$log = new WorkflowRunLog(1, 'step-id', []);
$log = new WorkflowRunLog(1, 'step-id');
$log->setData('key', 'value');
$log->setData('key2', ['arrayData']);
$preSave = $log->toArray();
@@ -26,7 +26,7 @@ class WorkflowRunLogStorageTest extends \MailPoetTest {
}
public function testItCanStoreAnError() {
$log = new WorkflowRunLog(1, 'step-id', []);
$log = new WorkflowRunLog(1, 'step-id');
$log->setError(new \Exception('test'));
$id = $this->storage->createWorkflowRunLog($log);
$log = $this->storage->getWorkflowRunLog($id);