canPush()) { return $this->_push($data, $queueName); } else { throw new Exception("Max Jobs number exceed! the max Jobs number is {$this->maxJob}"); } } /** * 延时入队列 * @param $delay * @param string $data * @param $queueName * @return mixed * @throws Exception */ public function later($delay, array $data = [], $queue = null) { if ($this->canPush()) { return $this->_later($delay, $data, $queue); } else { throw new Exception("Max Jobs number exceed! the max Jobs number is {$this->maxJob}"); } } /** * 将任务及任务相关数据打包成json数据 * @param mixed $data * @return string */ protected function createPayload(array $data = []) { return json_encode($data, JSON_UNESCAPED_UNICODE); } /** * 准备任务的数据 * @param $data * @return array */ protected function prepareQueueData(array $data) { $data = array_map(function ($d) { if (is_array($d)) { return $this->prepareQueueData($d); } return $d; }, $data); return $data; } /** * 检查队列是否已达最大任务量 * @return bool */ protected function canPush() { if ($this->maxJob > 0 && $this->getJobCount() >= $this->maxJob) { return false; } return true; } /** * 获取队列名称 * @param $queueName * @return string */ protected function getQueueName($queueName) { return $queueName ?: $this->queueName; } }