diff --git a/ProcessMaker/Jobs/RefreshArtisanCaches.php b/ProcessMaker/Jobs/RefreshArtisanCaches.php index 6aeb31e5e0..074c569db1 100644 --- a/ProcessMaker/Jobs/RefreshArtisanCaches.php +++ b/ProcessMaker/Jobs/RefreshArtisanCaches.php @@ -10,36 +10,10 @@ use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Support\Facades\Artisan; -class RefreshArtisanCaches implements ShouldQueue, ShouldBeUnique +class RefreshArtisanCaches implements ShouldQueue { use Dispatchable, InteractsWithQueue, Queueable; - public $tries = 2; // One extra try to handle the debounce release - - public $queuedAt; - - /** - * Create a new job instance. - * - * @return void - */ - public function __construct() - { - $this->queuedAt = time(); - } - - /** - * Debounce when multiple Settings are saved at the same time - * - * @return array - */ - public function middleware(): array - { - return [ - (new WithoutOverlapping('refresh_artisan_caches'))->dontRelease(), - ]; - } - /** * Execute the job. * @@ -54,13 +28,6 @@ public function handle() return; } - // Wait 3 seconds before running the job - debounce - if ($this->queuedAt && $this->queuedAt >= time() - 3) { - $this->release(3); - - return; - } - $options = [ '--no-interaction' => true, '--quiet' => true, diff --git a/ProcessMaker/Observers/SettingObserver.php b/ProcessMaker/Observers/SettingObserver.php index 6d56af975a..e4144ab3fb 100644 --- a/ProcessMaker/Observers/SettingObserver.php +++ b/ProcessMaker/Observers/SettingObserver.php @@ -10,6 +10,8 @@ class SettingObserver { + private static $added_refresh_artisan_caches = false; + /** * Handle the setting "created" event. * @@ -91,6 +93,19 @@ private function invalidateSettingCache(Setting $setting) $key = $settingCache->createKey(['key' => $setting->key]); $settingCache->invalidate(['key' => $key]); - RefreshArtisanCaches::dispatch(); + // Check to see if we already added the refresh to the app's terminating queue. + // This is important for install commands when multiple settings are being created/updated. + if (self::$added_refresh_artisan_caches) { + return; + } + + // Use app()->terminating to ensure the cache is refreshed after the settings have been saved. + app()->terminating(function () { + // Do this synchronously so we dont have to wait after settings have been saved. + // This command runs pretty fast and only when an admin is updating settings. + RefreshArtisanCaches::dispatchSync(); + }); + + self::$added_refresh_artisan_caches = true; } }