complains.php + confirm_resend.php add lock

This commit is contained in:
xiaomlove
2025-09-21 14:43:00 +07:00
parent d16a864841
commit c74c36d434
5 changed files with 39 additions and 2 deletions
+14
View File
@@ -2,6 +2,7 @@
namespace Nexus\Database;
use App\Exceptions\LockFailException;
use Illuminate\Cache\LuaScripts;
use Illuminate\Cache\RedisLock;
@@ -47,4 +48,17 @@ class NexusLock extends RedisLock
return (bool) $this->redis->eval(LuaScripts::releaseLock(), [$this->name, $this->owner], 1);
}
/**
* @throws LockFailException
*/
public static function lockOrFail($name, $seconds, $owner = null): NexusLock
{
$lock = new self($name, $seconds, $owner);
if (!$lock->acquire()) {
do_log("$name failed to acquire lock", 'error');
throw new LockFailException($name, $lock->owner());
}
return $lock;
}
}