getRedis(); if (is_array($handler) && is_string($handler[0])) { $handler[0] = Snowflake::createObject($handler[0]); } $executeTime = time() + $tickTime; $crontab = new Crontab(); $crontab->max_execute_number = $max_execute_number; $crontab->handler = $handler; $crontab->params = $params; $crontab->tickTime = $tickTime; $crontab->isLoop = $isLoop; $redis->zAdd('system:crontab', (string)$executeTime, serialize($crontab)); } /** * @throws Exception */ public function execute(): void { $redis = Snowflake::app()->getRedis(); try { $this->execute_number += 1; call_user_func($this->handler, $list['params'] ?? null); if ($this->isLoop === false) { return; } if ($this->max_execute_number === -1) { $redis->zAdd('system:crontab', time() + $this->tickTime, serialize($this)); } else if ($this->execute_number < $this->max_execute_number) { $redis->zAdd('system:crontab', time() + $this->tickTime, serialize($this)); } } catch (\Throwable $throwable) { $this->addError($throwable->getMessage()); } finally { $redis->release(); } } }