mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 17:24:03 +00:00
Try fixing Queue issue
This commit is contained in:
parent
0442be42de
commit
2a1e2a727e
2 changed files with 18 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\Bootstrappers;
|
|||
|
||||
use Illuminate\Config\Repository;
|
||||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Queue\Events\JobProcessing;
|
||||
use Illuminate\Queue\QueueManager;
|
||||
use Illuminate\Support\Testing\Fakes\QueueFake;
|
||||
|
|
@ -25,19 +26,27 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
/** @var Dispatcher */
|
||||
protected $event;
|
||||
|
||||
public function __construct(Repository $config, QueueManager $queue, Dispatcher $event)
|
||||
/**
|
||||
* The normal constructor is only executed after tenancy is bootstrapped.
|
||||
* However, we're registering a hook to initialize tenancy. Therefore,
|
||||
* we need to register the hook at service provider execution time.
|
||||
*/
|
||||
public static function __constructStatic(Application $app)
|
||||
{
|
||||
static::setUpJobListener($app->make(Dispatcher::class));
|
||||
}
|
||||
|
||||
public function __construct(Repository $config, QueueManager $queue)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->queue = $queue;
|
||||
$this->event = $event;
|
||||
|
||||
$this->setUpJobListener();
|
||||
$this->setUpPayloadGenerator();
|
||||
}
|
||||
|
||||
protected function setUpJobListener()
|
||||
protected static function setUpJobListener($dispatcher)
|
||||
{
|
||||
$this->event->listen(JobProcessing::class, function ($event) {
|
||||
$dispatcher->listen(JobProcessing::class, function ($event) {
|
||||
$tenantId = $event->job->payload()['tenant_id'] ?? null;
|
||||
|
||||
// The job is not tenant-aware
|
||||
|
|
|
|||
|
|
@ -41,6 +41,10 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
|
||||
// Make sure bootstrappers are stateful (singletons).
|
||||
foreach ($this->app['config']['tenancy.bootstrappers'] ?? [] as $bootstrapper) {
|
||||
if (method_exists($bootstrapper, '__constructStatic')) {
|
||||
$bootstrapper::__constructStatic($this->app);
|
||||
}
|
||||
|
||||
$this->app->singleton($bootstrapper);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue