diff --git a/ProcessMaker/Jobs/RefreshArtisanCaches.php b/ProcessMaker/Jobs/RefreshArtisanCaches.php index 230767969e..0ca44566dc 100644 --- a/ProcessMaker/Jobs/RefreshArtisanCaches.php +++ b/ProcessMaker/Jobs/RefreshArtisanCaches.php @@ -6,6 +6,7 @@ use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; +use Illuminate\Queue\Middleware\WithoutOverlapping; use Illuminate\Support\Facades\Artisan; class RefreshArtisanCaches implements ShouldQueue @@ -24,6 +25,16 @@ public function __construct() // } + /** + * 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. * @@ -38,12 +49,7 @@ public function handle() if (app()->configurationIsCached()) { Artisan::call('config:cache', $options); - } else { - Artisan::call('queue:restart', $options); - - // We call this manually here since this job is dispatched - // automatically when the config *is* cached - RestartMessageConsumers::dispatchSync(); } + Artisan::call('queue:restart', $options); } } diff --git a/ProcessMaker/Observers/SettingObserver.php b/ProcessMaker/Observers/SettingObserver.php index 72c4d08064..6d56af975a 100644 --- a/ProcessMaker/Observers/SettingObserver.php +++ b/ProcessMaker/Observers/SettingObserver.php @@ -5,6 +5,7 @@ use Exception; use Illuminate\Support\Facades\Log; use ProcessMaker\Cache\Settings\SettingCacheFactory; +use ProcessMaker\Jobs\RefreshArtisanCaches; use ProcessMaker\Models\Setting; class SettingObserver @@ -89,5 +90,7 @@ private function invalidateSettingCache(Setting $setting) // Invalidate the setting cache $key = $settingCache->createKey(['key' => $setting->key]); $settingCache->invalidate(['key' => $key]); + + RefreshArtisanCaches::dispatch(); } }