From efc2461cb9b994b994e445ae70dbbec62e5a36cb Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 18 Nov 2025 09:37:12 -0800 Subject: [PATCH 1/2] Use queue:listen instead of queue:work for multitenancy --- ProcessMaker/Application.php | 7 --- .../Console/Commands/HorizonListen.php | 51 +++++++++++++++++++ .../Providers/ProcessMakerServiceProvider.php | 27 ++++++---- 3 files changed, 68 insertions(+), 17 deletions(-) create mode 100644 ProcessMaker/Console/Commands/HorizonListen.php diff --git a/ProcessMaker/Application.php b/ProcessMaker/Application.php index 87f85281df..5cea34ac9a 100644 --- a/ProcessMaker/Application.php +++ b/ProcessMaker/Application.php @@ -114,11 +114,4 @@ public function bootstrapWith(array $bootstrappers) return parent::bootstrapWith($bootstrappers); } - - public function reactivateConsoleApp() - { - Container::setInstance($this); - $this->hasBeenBootstrapped = false; - $this->make(Kernel::class)->bootstrap(); - } } diff --git a/ProcessMaker/Console/Commands/HorizonListen.php b/ProcessMaker/Console/Commands/HorizonListen.php new file mode 100644 index 0000000000..a3f3dd47b1 --- /dev/null +++ b/ProcessMaker/Console/Commands/HorizonListen.php @@ -0,0 +1,51 @@ +app->instance('tenant-resolved', false); + + if (config('app.multitenancy')) { + // Use queue:listen for multitenancy + $this->app->when(HorizonListen::class)->needs(Listener::class)->give(function ($app) { + return new Listener(base_path()); + }); + WorkerCommandString::$command = 'exec @php artisan horizon:listen'; + SystemProcessCounter::$command = 'horizon:listen'; + } } /** @@ -261,13 +271,10 @@ private static function bootstrapTenantApp(JobProcessing|JobRetryRequested $even // Create a new tenant app instance $_SERVER['TENANT'] = $tenantId; - if (!isset(self::$tenantAppContainers[$tenantId])) { - self::$tenantAppContainers[$tenantId] = require base_path('bootstrap/app.php'); - } - self::$tenantAppContainers[$tenantId]->reactivateConsoleApp(); - - // Change the job's app service container to the tenant app - $event->job->getRedisQueue()->setContainer(self::$tenantAppContainers[$tenantId]); + $app = require base_path('bootstrap/app.php'); + $app->make(\ProcessMaker\Console\Kernel::class)->bootstrap(); + \Illuminate\Container\Container::setInstance($app); + $event->job->getRedisQueue()->setContainer($app); } } From c68b0ad90c9b752bd3b7024ac42a819e4f7872d5 Mon Sep 17 00:00:00 2001 From: Nolan Ehrstrom Date: Tue, 18 Nov 2025 11:59:08 -0800 Subject: [PATCH 2/2] Always register the listener service --- ProcessMaker/Providers/ProcessMakerServiceProvider.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ProcessMaker/Providers/ProcessMakerServiceProvider.php b/ProcessMaker/Providers/ProcessMakerServiceProvider.php index 9ece18331b..497020110b 100644 --- a/ProcessMaker/Providers/ProcessMakerServiceProvider.php +++ b/ProcessMaker/Providers/ProcessMakerServiceProvider.php @@ -243,11 +243,11 @@ public function register(): void $this->app->instance('tenant-resolved', false); + $this->app->when(HorizonListen::class)->needs(Listener::class)->give(function ($app) { + return new Listener(base_path()); + }); + if (config('app.multitenancy')) { - // Use queue:listen for multitenancy - $this->app->when(HorizonListen::class)->needs(Listener::class)->give(function ($app) { - return new Listener(base_path()); - }); WorkerCommandString::$command = 'exec @php artisan horizon:listen'; SystemProcessCounter::$command = 'horizon:listen'; }