Only expose log in post-step hook
The log has step ID and workflow run ID in case an integration needs to retrieve them. [MAILPOET-4463]
This commit is contained in:
committed by
Jan Jakeš
parent
6f8edfaec4
commit
57cf547a8a
@ -130,7 +130,7 @@ class StepHandler {
|
|||||||
throw $e;
|
throw $e;
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
$this->hooks->doWorkflowStepAfterRun($step, $log);
|
$this->hooks->doWorkflowStepAfterRun($log);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$log->addError($e);
|
$log->addError($e);
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class Hooks {
|
|||||||
$this->wordPress->doAction(self::WORKFLOW_STEP_BEFORE_SAVE . '/key=' . $step->getKey(), $step);
|
$this->wordPress->doAction(self::WORKFLOW_STEP_BEFORE_SAVE . '/key=' . $step->getKey(), $step);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function doWorkflowStepAfterRun(Step $step, WorkflowRunLog $workflowRunLog): void {
|
public function doWorkflowStepAfterRun(WorkflowRunLog $workflowRunLog): void {
|
||||||
$this->wordPress->doAction(self::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, $step, $workflowRunLog);
|
$this->wordPress->doAction(self::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, $workflowRunLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,9 @@ class WorkflowRunLogTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testItGetsExposedViaAction(): void {
|
public function testItGetsExposedViaAction(): void {
|
||||||
$this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(Step $step, WorkflowRunLog $log) {
|
$this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(WorkflowRunLog $log) {
|
||||||
$log->setData('test', 'value');
|
$log->setData('test', 'value');
|
||||||
}, 10, 2);
|
});
|
||||||
$workflowRunLogs = $this->getLogsForAction();
|
$workflowRunLogs = $this->getLogsForAction();
|
||||||
expect($workflowRunLogs)->count(1);
|
expect($workflowRunLogs)->count(1);
|
||||||
$log = $workflowRunLogs[0];
|
$log = $workflowRunLogs[0];
|
||||||
@ -69,9 +69,9 @@ class WorkflowRunLogTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testBadActionIntegrationsCannotDerailStepFromRunning() {
|
public function testBadActionIntegrationsCannotDerailStepFromRunning() {
|
||||||
$this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(Step $step, WorkflowRunLog $log) {
|
$this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(WorkflowRunLog $log) {
|
||||||
throw new \Exception('bad integration');
|
throw new \Exception('bad integration');
|
||||||
}, 9, 2);
|
});
|
||||||
$workflowRunLogs = $this->getLogsForAction();
|
$workflowRunLogs = $this->getLogsForAction();
|
||||||
expect($workflowRunLogs)->count(1);
|
expect($workflowRunLogs)->count(1);
|
||||||
$log = $workflowRunLogs[0];
|
$log = $workflowRunLogs[0];
|
||||||
@ -99,21 +99,17 @@ class WorkflowRunLogTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testItLogsCompletedStatusCorrectly(): void {
|
public function testItLogsCompletedStatusCorrectly(): void {
|
||||||
$workflowRunLogs = $this->getLogsForAction(function() {
|
$workflowRunLogs = $this->getLogsForAction();
|
||||||
return true;
|
|
||||||
});
|
|
||||||
expect($workflowRunLogs)->count(1);
|
expect($workflowRunLogs)->count(1);
|
||||||
$log = $workflowRunLogs[0];
|
$log = $workflowRunLogs[0];
|
||||||
expect($log->getStatus())->equals('completed');
|
expect($log->getStatus())->equals('completed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testItAddsCompletedAtTimestampAfterRunningSuccessfully(): void {
|
public function testItAddsCompletedAtTimestampAfterRunningSuccessfully(): void {
|
||||||
$this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(Step $step, WorkflowRunLog $log) {
|
$this->wp->addAction(Hooks::WORKFLOW_RUN_LOG_AFTER_STEP_RUN, function(WorkflowRunLog $log) {
|
||||||
expect($log->getCompletedAt())->null();
|
expect($log->getCompletedAt())->null();
|
||||||
}, 10, 2);
|
|
||||||
$workflowRunLogs = $this->getLogsForAction(function() {
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
$workflowRunLogs = $this->getLogsForAction();
|
||||||
expect($workflowRunLogs)->count(1);
|
expect($workflowRunLogs)->count(1);
|
||||||
$log = $workflowRunLogs[0];
|
$log = $workflowRunLogs[0];
|
||||||
expect($log->getCompletedAt())->isInstanceOf(\DateTimeImmutable::class);
|
expect($log->getCompletedAt())->isInstanceOf(\DateTimeImmutable::class);
|
||||||
@ -171,6 +167,9 @@ class WorkflowRunLogTest extends \MailPoetTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function getLogsForAction($callback = null) {
|
private function getLogsForAction($callback = null) {
|
||||||
|
if ($callback === null) {
|
||||||
|
$callback = function() { return true; };
|
||||||
|
}
|
||||||
$testAction = $this->getRegisteredTestAction($callback);
|
$testAction = $this->getRegisteredTestAction($callback);
|
||||||
$actionStep = new Step('action-step-id', Step::TYPE_ACTION, $testAction->getKey());
|
$actionStep = new Step('action-step-id', Step::TYPE_ACTION, $testAction->getKey());
|
||||||
$workflow = new Workflow('test_workflow', [$actionStep], new \WP_User());
|
$workflow = new Workflow('test_workflow', [$actionStep], new \WP_User());
|
||||||
|
Reference in New Issue
Block a user