mirror of
https://gitee.com/hyperf/hyperf.git
synced 2024-12-03 12:17:48 +08:00
parent
150d827fa1
commit
657b9c7138
@ -15,6 +15,9 @@ namespace Hyperf\Crontab\Mutex;
|
||||
use Hyperf\Crontab\Crontab;
|
||||
use Hyperf\Redis\RedisFactory;
|
||||
use Hyperf\Utils\Arr;
|
||||
use Hyperf\Utils\Coordinator\Constants;
|
||||
use Hyperf\Utils\Coordinator\CoordinatorManager;
|
||||
use Hyperf\Utils\Coroutine;
|
||||
|
||||
class RedisServerMutex implements ServerMutex
|
||||
{
|
||||
@ -50,6 +53,10 @@ class RedisServerMutex implements ServerMutex
|
||||
$result = (bool) $redis->set($mutexName, $this->macAddress, ['NX', 'EX' => $crontab->getMutexExpires()]);
|
||||
|
||||
if ($result === true) {
|
||||
Coroutine::create(function() use ($crontab, $redis, $mutexName) {
|
||||
$exited = CoordinatorManager::get(Constants::ON_WORKER_EXIT)->yield($crontab->getMutexExpires());
|
||||
$exited && $redis->del($mutexName);
|
||||
});
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user