添加 更新锁
This commit is contained in:
parent
b24f26866b
commit
c2e2185109
@ -6,6 +6,7 @@
|
||||
use App\Jobs\Host\HostJob;
|
||||
use App\Models\Host;
|
||||
use App\Notifications\WebNotification;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class HostObserver
|
||||
{
|
||||
@ -41,8 +42,15 @@ public function created(Host $host): void
|
||||
/**
|
||||
* Handle the Host "updated" event.
|
||||
*/
|
||||
public function updating(Host $host): void
|
||||
public function updating(Host $host): bool
|
||||
{
|
||||
// 取得锁
|
||||
$lock = Cache::lock('host:updating:'.$host->id, 10);
|
||||
|
||||
if (! $lock->get()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($host->isDirty('status')) {
|
||||
if ($host->status == 'suspended') {
|
||||
$host->suspended_at = now();
|
||||
@ -69,6 +77,11 @@ public function updating(Host $host): void
|
||||
}
|
||||
|
||||
broadcast(new Users($host->user_id, 'hosts.updating', $host));
|
||||
|
||||
// 释放锁
|
||||
$lock->release();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function updated(Host $host): void
|
||||
|
Loading…
Reference in New Issue
Block a user