From c89fc059438bf18b7af375872ef8e356503bbdfb Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Thu, 13 Oct 2022 02:44:36 +0300 Subject: [PATCH] Optimized logging --- src/Services/Migrator.php | 46 ++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/Services/Migrator.php b/src/Services/Migrator.php index 74b1d255..f4d52188 100644 --- a/src/Services/Migrator.php +++ b/src/Services/Migrator.php @@ -49,13 +49,15 @@ public function runUp(string $filename, int $batch, Options $options): void $name = $this->resolveActionName($path); if ($this->allowAction($action, $name, $options)) { - $this->hasAction($action, '__invoke') - ? $this->runAction($action, $name, '__invoke') - : $this->runAction($action, $name, 'up'); + $this->notification->task($name, function () use ($action, $name, $batch) { + $this->hasAction($action, '__invoke') + ? $this->runAction($action, '__invoke') + : $this->runAction($action, 'up'); - if ($this->allowLogging($action)) { - $this->log($name, $batch); - } + if ($this->allowLogging($action)) { + $this->log($name, $batch); + } + }); return; } @@ -69,11 +71,13 @@ public function runDown(string $filename, Options $options): void $action = $this->resolveAction($path); $name = $this->resolveActionName($path); - if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) { - $this->runAction($action, $name, 'down'); - } + $this->notification->task($name, function () use ($action, $name) { + if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) { + $this->runAction($action, 'down'); + } - $this->deleteLog($name); + $this->deleteLog($name); + }); } protected function hasAction(Action $action, string $method): bool @@ -81,22 +85,20 @@ protected function hasAction(Action $action, string $method): bool return method_exists($action, $method); } - protected function runAction(Action $action, string $name, string $method): void + protected function runAction(Action $action, string $method): void { - $this->notification->task($name, function () use ($action, $method) { - if ($this->hasAction($action, $method)) { - try { - $this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts()); + if ($this->hasAction($action, $method)) { + try { + $this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts()); - $action->success(); - } - catch (Throwable $e) { - $action->failed(); + $action->success(); + } + catch (Throwable $e) { + $action->failed(); - throw $e; - } + throw $e; } - }); + } } protected function runMethod(Action $action, string $method, bool $transactions, int $attempts): void