/** * 定时处理队列数据 * php yii emoticon/scrapy/pic-url */ public function actionPicUrl() { $list = EmoticonQueue::find()->where(['status' => -1])->orderBy(['id' => SORT_ASC])->limit(50)->all(); if (!$list) { return $this->echoLog('no data need to handle'); } $date_now = date("Y-m-d H:i:s"); foreach ($list as $_item) { $this->echoLog("queue_id:{$_item['id']}"); switch ($_item['type']) { case 1: $tmp_ret = EmoticonService::scrapy($_item); break; case 2: $tmp_ret = EmoticonService::parseImages($_item); break; default: $tmp_ret = false; break; } if (!$tmp_ret) { $this->echoLog(EmoticonService::getLastErrorMsg()); } $_item->status = $tmp_ret ? 1 : 0; $_item->updated_time = $date_now; $_item->update(0); } return $this->echoLog("it's over ~~"); }
public static function addQueue($params) { if (!$params || !isset($params['url'])) { return self::_err('url must be ~~'); } $uniq_key = md5($params['url']); $has_in = EmoticonQueue::find()->where(['uniq_key' => $uniq_key])->count(); if ($has_in) { return true; } $model_face = new EmoticonQueue(); $model_face->source = isset($params['source']) ? $params['source'] : 0; $model_face->type = isset($params['type']) ? $params['type'] : 0; $model_face->url = $params['url']; $model_face->uniq_key = $uniq_key; $model_face->status = -1; $model_face->updated_time = date("Y-m-d H:i:s"); $model_face->created_time = $model_face->updated_time; return $model_face->save(0); }