Skip to content

Commit

Permalink
fix: callback handlers for queue workers (#43)
Browse files Browse the repository at this point in the history
When using a queue worker, each notification resets the scope.
The problem here is that when this happens, all of the callbacks that were registered are no longer available - this is because they were all registered to a scoped singleton.
I'm not sure how anyone else is able to use this package with a queue worker - out of the box it only works on "sync" mode, unless we remove the scoped singleton.

In-fact, I'm curious as to why the singleton was scoped in the first place as part of the laravel 9 compatibility upgrades?
  • Loading branch information
gavinservai authored Jan 24, 2024
1 parent 82a4f15 commit 23f0f21
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/SubscribableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,9 @@ public function boot()
public function register()
{
$this->app->bind(MailChannel::class, SubscriberMailChannel::class);
if (method_exists($this->app, 'scoped')) {
$this->app->scoped(Subscriber::class, function (Application $app) {
return new Subscriber($app);
});
} else {
$this->app->singleton(Subscriber::class, function (Application $app) {
/** @phpstan-ignore-next-line */
return new Subscriber($app);
});
}
$this->app->singleton(Subscriber::class, function (Application $app) {
/** @phpstan-ignore-next-line */
return new Subscriber($app);
});
}
}

0 comments on commit 23f0f21

Please sign in to comment.