Skip to content

Commit

Permalink
Remove error message duplication for pipeline (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
marvin255 authored Jun 25, 2021
1 parent 663f5ca commit f273858
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions src/Pipeline/Pipe/ArrayPipe.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public function run(State $state): Pipe
*/
protected function proceedStart(State $state): void
{
$message = sprintf("Start '%s' pipeline with '%s' state.", \get_class($this), \get_class($state));
$message = sprintf(
"Start '%s' pipeline with '%s' state.",
\get_class($this),
\get_class($state)
);

$this->log(LogLevel::INFO, $message);
}

Expand All @@ -104,17 +109,24 @@ protected function proceedStart(State $state): void
protected function proceedTask(State $state, Task $task): void
{
$taskName = $this->getTaskId($task);

$this->log(
LogLevel::INFO,
"Start '{$taskName}' task.",
['task' => $taskName]
[
'task' => $taskName,
]
);

$this->injectLoggerToTask($task);
$task->run($state);

$this->log(
LogLevel::INFO,
"Complete '{$taskName}' task.",
['task' => $taskName]
[
'task' => $taskName,
]
);
}

Expand All @@ -130,12 +142,16 @@ protected function proceedTask(State $state, Task $task): void
protected function proceedException(State $state, Task $task, Throwable $e): void
{
$taskName = $this->getTaskId($task);
$message = "Error while running {$taskName} task: {$e->getMessage()}";
$message = "Error while running {$taskName} task.";

$this->log(LogLevel::ERROR, $message, [
'exception' => $e,
'task' => $taskName,
]);
$this->log(
LogLevel::ERROR,
$message,
[
'exception' => $e,
'task' => $taskName,
]
);

$this->proceedCleanup($state);

Expand Down Expand Up @@ -195,7 +211,11 @@ protected function injectLoggerToTask(Task $task): void
if ($task instanceof LoggableTask && $this->logger) {
$task->injectLogger(
$this->logger,
$this->createLoggerContext(['task' => $this->getTaskId($task)])
$this->createLoggerContext(
[
'task' => $this->getTaskId($task),
]
)
);
}
}
Expand Down

0 comments on commit f273858

Please sign in to comment.