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
35 changes: 1 addition & 34 deletions ProcessMaker/Jobs/RefreshArtisanCaches.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, object>
*/
public function middleware(): array
{
return [
(new WithoutOverlapping('refresh_artisan_caches'))->dontRelease(),
];
}

/**
* Execute the job.
*
Expand All @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion ProcessMaker/Observers/SettingObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

class SettingObserver
{
private static $added_refresh_artisan_caches = false;

/**
* Handle the setting "created" event.
*
Expand Down Expand Up @@ -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;
}
}