mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 19:34:04 +00:00
[1.8.0] Add Queue support & Horizon integration (#104)
This commit is contained in:
parent
d04f4bb2a1
commit
8d8c177dac
2 changed files with 85 additions and 0 deletions
|
|
@ -50,6 +50,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
$this->app->register(TenantRouteServiceProvider::class);
|
||||
|
||||
$this->registerTenantRedirectMacro();
|
||||
$this->makeQueuesTenantAware();
|
||||
}
|
||||
|
||||
public function registerTenantRedirectMacro()
|
||||
|
|
@ -65,6 +66,31 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
});
|
||||
}
|
||||
|
||||
public function makeQueuesTenantAware()
|
||||
{
|
||||
$this->app['queue']->createPayloadUsing(function () {
|
||||
if (tenancy()->initialized) {
|
||||
[$uuid, $domain] = tenant()->get(['uuid', 'domain']);
|
||||
|
||||
return [
|
||||
'tenant_uuid' => $uuid,
|
||||
'tags' => [
|
||||
"tenant:$uuid",
|
||||
"domain:$domain",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
});
|
||||
|
||||
$this->app['events']->listen(\Illuminate\Queue\Events\JobProcessing::class, function ($event) {
|
||||
if (\array_key_exists('tenant_uuid', $event->job->payload())) {
|
||||
tenancy()->initById($event->job->payload()['tenant_uuid']);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue