Skip to content

Commit 6659ce0

Browse files
authored
Merge pull request #8559 from ProcessMaker/bugfix/FOUR-27150
Refresh config cache in synchronously
2 parents 38b777f + 4e4a758 commit 6659ce0

2 files changed

Lines changed: 17 additions & 35 deletions

File tree

ProcessMaker/Jobs/RefreshArtisanCaches.php

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,10 @@
1010
use Illuminate\Queue\Middleware\WithoutOverlapping;
1111
use Illuminate\Support\Facades\Artisan;
1212

13-
class RefreshArtisanCaches implements ShouldQueue, ShouldBeUnique
13+
class RefreshArtisanCaches implements ShouldQueue
1414
{
1515
use Dispatchable, InteractsWithQueue, Queueable;
1616

17-
public $tries = 2; // One extra try to handle the debounce release
18-
19-
public $queuedAt;
20-
21-
/**
22-
* Create a new job instance.
23-
*
24-
* @return void
25-
*/
26-
public function __construct()
27-
{
28-
$this->queuedAt = time();
29-
}
30-
31-
/**
32-
* Debounce when multiple Settings are saved at the same time
33-
*
34-
* @return array<int, object>
35-
*/
36-
public function middleware(): array
37-
{
38-
return [
39-
(new WithoutOverlapping('refresh_artisan_caches'))->dontRelease(),
40-
];
41-
}
42-
4317
/**
4418
* Execute the job.
4519
*
@@ -54,13 +28,6 @@ public function handle()
5428
return;
5529
}
5630

57-
// Wait 3 seconds before running the job - debounce
58-
if ($this->queuedAt && $this->queuedAt >= time() - 3) {
59-
$this->release(3);
60-
61-
return;
62-
}
63-
6431
$options = [
6532
'--no-interaction' => true,
6633
'--quiet' => true,

ProcessMaker/Observers/SettingObserver.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
class SettingObserver
1212
{
13+
private static $added_refresh_artisan_caches = false;
14+
1315
/**
1416
* Handle the setting "created" event.
1517
*
@@ -91,6 +93,19 @@ private function invalidateSettingCache(Setting $setting)
9193
$key = $settingCache->createKey(['key' => $setting->key]);
9294
$settingCache->invalidate(['key' => $key]);
9395

94-
RefreshArtisanCaches::dispatch();
96+
// Check to see if we already added the refresh to the app's terminating queue.
97+
// This is important for install commands when multiple settings are being created/updated.
98+
if (self::$added_refresh_artisan_caches) {
99+
return;
100+
}
101+
102+
// Use app()->terminating to ensure the cache is refreshed after the settings have been saved.
103+
app()->terminating(function () {
104+
// Do this synchronously so we dont have to wait after settings have been saved.
105+
// This command runs pretty fast and only when an admin is updating settings.
106+
RefreshArtisanCaches::dispatchSync();
107+
});
108+
109+
self::$added_refresh_artisan_caches = true;
95110
}
96111
}

0 commit comments

Comments
 (0)