Skip to content

Commit 58516e7

Browse files
authored
Reset application scope to flush scoped instances (#313)
* reset application scope to flush scoped instances * wip * wip * Apply fixes from StyleCI (#314) * fix style
1 parent 46ef9bd commit 58516e7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Listeners/FlushTemporaryContainerInstances.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ class FlushTemporaryContainerInstances
1212
*/
1313
public function handle($event): void
1414
{
15+
if (method_exists($event->app, 'resetScope')) {
16+
$event->app->resetScope();
17+
}
18+
1519
foreach ($event->sandbox->make('config')->get('octane.flush', []) as $binding) {
1620
$event->app->forgetInstance($binding);
17-
$event->sandbox->forgetInstance($binding);
1821
}
1922
}
2023
}

src/Worker.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ public function handleTask($data)
151151

152152
return TaskExceptionResult::from($e);
153153
} finally {
154+
$sandbox->flush();
155+
154156
// After the request handling process has completed we will unset some variables
155157
// plus reset the current application state back to its original state before
156158
// it was cloned. Then we will be ready for the next worker iteration loop.
@@ -177,6 +179,8 @@ public function handleTick(): void
177179
} catch (Throwable $e) {
178180
$this->dispatchEvent($sandbox, new WorkerErrorOccurred($e, $sandbox));
179181
} finally {
182+
$sandbox->flush();
183+
180184
unset($sandbox);
181185

182186
CurrentApplication::set($this->app);

0 commit comments

Comments
 (0)