Skip to content

Commit c89fc05

Browse files
Optimized logging
1 parent 89e05dd commit c89fc05

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

src/Services/Migrator.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,15 @@ public function runUp(string $filename, int $batch, Options $options): void
4949
$name = $this->resolveActionName($path);
5050

5151
if ($this->allowAction($action, $name, $options)) {
52-
$this->hasAction($action, '__invoke')
53-
? $this->runAction($action, $name, '__invoke')
54-
: $this->runAction($action, $name, 'up');
52+
$this->notification->task($name, function () use ($action, $name, $batch) {
53+
$this->hasAction($action, '__invoke')
54+
? $this->runAction($action, '__invoke')
55+
: $this->runAction($action, 'up');
5556

56-
if ($this->allowLogging($action)) {
57-
$this->log($name, $batch);
58-
}
57+
if ($this->allowLogging($action)) {
58+
$this->log($name, $batch);
59+
}
60+
});
5961

6062
return;
6163
}
@@ -69,34 +71,34 @@ public function runDown(string $filename, Options $options): void
6971
$action = $this->resolveAction($path);
7072
$name = $this->resolveActionName($path);
7173

72-
if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) {
73-
$this->runAction($action, $name, 'down');
74-
}
74+
$this->notification->task($name, function () use ($action, $name) {
75+
if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) {
76+
$this->runAction($action, 'down');
77+
}
7578

76-
$this->deleteLog($name);
79+
$this->deleteLog($name);
80+
});
7781
}
7882

7983
protected function hasAction(Action $action, string $method): bool
8084
{
8185
return method_exists($action, $method);
8286
}
8387

84-
protected function runAction(Action $action, string $name, string $method): void
88+
protected function runAction(Action $action, string $method): void
8589
{
86-
$this->notification->task($name, function () use ($action, $method) {
87-
if ($this->hasAction($action, $method)) {
88-
try {
89-
$this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts());
90+
if ($this->hasAction($action, $method)) {
91+
try {
92+
$this->runMethod($action, $method, $action->enabledTransactions(), $action->transactionAttempts());
9093

91-
$action->success();
92-
}
93-
catch (Throwable $e) {
94-
$action->failed();
94+
$action->success();
95+
}
96+
catch (Throwable $e) {
97+
$action->failed();
9598

96-
throw $e;
97-
}
99+
throw $e;
98100
}
99-
});
101+
}
100102
}
101103

102104
protected function runMethod(Action $action, string $method, bool $transactions, int $attempts): void

0 commit comments

Comments
 (0)