Signed-off-by: reasno <guxi99@gmail.com>
This commit is contained in:
reasno 2020-04-13 23:52:08 +08:00
parent 150d827fa1
commit 657b9c7138

View File

@ -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;
}