Skip to content

Commit

Permalink
Reset application scope to flush scoped instances (#313)
Browse files Browse the repository at this point in the history
* reset application scope to flush scoped instances

* wip

* wip

* Apply fixes from StyleCI (#314)

* fix style
  • Loading branch information
themsaid authored Jun 10, 2021
1 parent 46ef9bd commit 58516e7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Listeners/FlushTemporaryContainerInstances.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class FlushTemporaryContainerInstances
*/
public function handle($event): void
{
if (method_exists($event->app, 'resetScope')) {
$event->app->resetScope();
}

foreach ($event->sandbox->make('config')->get('octane.flush', []) as $binding) {
$event->app->forgetInstance($binding);
$event->sandbox->forgetInstance($binding);
}
}
}
4 changes: 4 additions & 0 deletions src/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ public function handleTask($data)

return TaskExceptionResult::from($e);
} finally {
$sandbox->flush();

// After the request handling process has completed we will unset some variables
// plus reset the current application state back to its original state before
// it was cloned. Then we will be ready for the next worker iteration loop.
Expand All @@ -177,6 +179,8 @@ public function handleTick(): void
} catch (Throwable $e) {
$this->dispatchEvent($sandbox, new WorkerErrorOccurred($e, $sandbox));
} finally {
$sandbox->flush();

unset($sandbox);

CurrentApplication::set($this->app);
Expand Down

0 comments on commit 58516e7

Please sign in to comment.