Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions ProcessMaker/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
51 changes: 51 additions & 0 deletions ProcessMaker/Console/Commands/HorizonListen.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace ProcessMaker\Console\Commands;

use Illuminate\Queue\Console\ListenCommand as BaseCommand;

// https://github.com/laravel/horizon/issues/624
class HorizonListen extends BaseCommand
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'horizon:listen
{connection? : The name of connection}
{--name=default : The name of the worker}
{--delay=0 : The number of seconds to delay failed jobs (Deprecated)}
{--backoff=0 : The number of seconds to wait before retrying a job that encountered an uncaught exception}
{--max-time=0 : The maximum number of seconds the worker should run}
{--max-jobs=0 : The number of jobs to process before stopping}
{--force : Force the worker to run even in maintenance mode}
{--memory=128 : The memory limit in megabytes}
{--queue= : The queue to listen on}
{--sleep=3 : Number of seconds to sleep when no job is available}
{--timeout=60 : The number of seconds a child process can run}
{--tries=1 : Number of times to attempt a job before logging it failed}
{--supervisor= : The name of the supervisor the worker belongs to}
{--rest=0 : Number of seconds to rest between jobs}';

/**
* Indicates whether the command should be shown in the Artisan command list.
*
* @var bool
*/
protected $hidden = true;

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if (config('horizon.fast_termination')) {
ignore_user_abort(true);
}

parent::handle();
}
}
27 changes: 17 additions & 10 deletions ProcessMaker/Providers/ProcessMakerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Queue\Events\JobAttempted;
use Illuminate\Queue\Events\JobProcessing;
use Illuminate\Queue\Events\JobRetryRequested;
use Illuminate\Queue\Listener;
use Illuminate\Support\Arr;
use Illuminate\Support\Env;
use Illuminate\Support\Facades;
Expand All @@ -22,8 +23,11 @@
use Illuminate\Support\Facades\URL;
use Laravel\Dusk\DuskServiceProvider;
use Laravel\Horizon\Horizon;
use Laravel\Horizon\SystemProcessCounter;
use Laravel\Horizon\WorkerCommandString;
use Lavary\Menu\Menu;
use ProcessMaker\Cache\Settings\SettingCacheManager;
use ProcessMaker\Console\Commands\HorizonListen;
use ProcessMaker\Console\Migration\ExtendedMigrateCommand;
use ProcessMaker\Events\ActivityAssigned;
use ProcessMaker\Events\ScreenBuilderStarting;
Expand Down Expand Up @@ -71,9 +75,6 @@ class ProcessMakerServiceProvider extends ServiceProvider
// Track the landlord values for multitenancy
private static $landlordValues = null;

// Cache tenant app containers to save memory
private static $tenantAppContainers = [];

public function boot(): void
{
// Track the start time for service providers boot
Expand Down Expand Up @@ -241,6 +242,15 @@ 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')) {
WorkerCommandString::$command = 'exec @php artisan horizon:listen';
SystemProcessCounter::$command = 'horizon:listen';
}
}

/**
Expand All @@ -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);
}
}

Expand Down
Loading