Skip to content

Commit

Permalink
Optimized logging
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Oct 12, 2022
1 parent 89e05dd commit c89fc05
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/Services/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -69,34 +71,34 @@ 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
{
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
Expand Down

0 comments on commit c89fc05

Please sign in to comment.