/** * Redis获取未处理队列数 * @return int */ private function getRedisNoDealTaskdNum() { $redisQueueBll = Bll_House_UpDown_RedisQueueBll::get_instance(); $queues = $redisQueueBll->queues(); if (empty($queues)) { return 0; } $num = 0; foreach ($queues as $queue) { $num += $redisQueueBll->length($queue); } return $num; }
public function handle_request() { // 初始化开始和结束日期 $startDate = $this->cursor->date; $endDate = $this->cursor->date; // 获取截止日期 $redisQueueBll = Bll_House_UpDown_RedisQueueBll::get_instance(); $queues = $redisQueueBll->queues(); foreach ($queues as $queue) { $result = $redisQueueBll->clear($queue); if (isset($result['old']) && $result['old']) { $rawColumnTask = json_decode($result['old'], true); $tmpEndDate = date('Y-m-d', $rawColumnTask['add_date']); if ($this->compareDate($endDate, $tmpEndDate) > 0) { $endDate = $tmpEndDate; } } } // 获取开始ID $startId = Model_House_UpDown_Task::data_access(date('Ymd', strtotime($startDate)))->filter('flag', 1)->max('id'); $startId += 1; do { $tasks = Model_House_UpDown_Task::data_access(date('Ymd', strtotime($startDate)))->filter_by_op('id', '<', $startId)->filter('flag', 1)->limit($this->per)->sort('id', 'desc')->find_all(); if (empty($tasks)) { // 如果 StartDate > EndDate,更新游标 if ($this->compareDate($startDate, $endDate) > 0) { $startDate = date('Y-m-d', strtotime('-1 day', strtotime($startDate))); $startId = Model_House_UpDown_Task::data_access(date('Ymd', strtotime($startDate)))->filter('flag', 1)->max('id'); $startId += 1; // 更新游标 $this->cursor->setDate($startDate)->setId($startId)->save(); } else { // 如果 StartDate 和 EndDate 相等,说明初始化结束 $this->cursor->setId($startId - 1)->save(); break; } } foreach ($tasks as $task) { $task->flag = 0; $task->save(); // 更新游标 $startId = $task->id; $this->cursor->setId($startId)->save(); } } while (true); }
/** * 根据外部传过来的队列名从redis中获取相应的信息 * @param $queue 队列名 * @return array */ protected function readQueueInfo($queue) { $RedisQueueBll = Bll_House_UpDown_RedisQueueBll::get_instance(); return $RedisQueueBll->dequeue($queue); }
/** * 初始化环境 */ protected function init() { $this->initOptions(); $this->cursor = Bll_House_UpDown_DispatcherCursorBll::get_instance(); $this->redisQueueBll = Bll_House_UpDown_RedisQueueBll::get_instance(); }