添加ADParserSelect
This commit is contained in:
parent
06c62b87e9
commit
f30ecc41a2
56
logdb.go
56
logdb.go
|
@ -19,13 +19,17 @@ type LogDB struct {
|
|||
Port string `yaml:"port"`
|
||||
User string `yaml:"user"`
|
||||
|
||||
hostid int
|
||||
driver *sql.DB
|
||||
hostid int
|
||||
nextCheck int64
|
||||
checkLimit int64
|
||||
driver *sql.DB
|
||||
}
|
||||
|
||||
// New 创建一个logdb的配置
|
||||
func New(filename string) *LogDB {
|
||||
logdb := LogDB{}
|
||||
logdb.checkLimit = 300
|
||||
|
||||
data, err := ioutil.ReadFile(filename)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -99,6 +103,52 @@ func (logdb *LogDB) ADInsert(uid, device, platform, area_cc, section_id, respons
|
|||
}
|
||||
}
|
||||
|
||||
type ADResonse struct {
|
||||
UID string
|
||||
Response string
|
||||
}
|
||||
|
||||
func (logdb *LogDB) ADParserSelect(pid, spider_id int) []ADResonse {
|
||||
|
||||
// pid := os.Getpid() + 2000
|
||||
// spiderid := 73 + 1000000
|
||||
logdb.ADCheckError(spider_id)
|
||||
|
||||
_, err := logdb.driver.Exec("update log_spider set status = ? where spider_id = ? and status = 0 limit 100", pid, spider_id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
rows, err := logdb.driver.Query("select uid, response from log_spider where spider_id = ? and status = ?", spider_id, pid)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
var adresponse []ADResonse
|
||||
|
||||
var uid, response string
|
||||
for rows.Next() {
|
||||
rows.Scan(&uid, &response)
|
||||
adresponse = append(adresponse, ADResonse{UID: uid, Response: response})
|
||||
// log.Println(uid, response)
|
||||
}
|
||||
|
||||
return adresponse
|
||||
}
|
||||
|
||||
func (logdb *LogDB) ADCheckError(spider_id int) {
|
||||
now := time.Now()
|
||||
if now.Unix() > logdb.nextCheck {
|
||||
logdb.nextCheck = now.Unix() + logdb.checkLimit
|
||||
|
||||
tsUpdate := now.Add(-time.Minute * 5)
|
||||
_, err := logdb.driver.Exec("update status = 0, error_msg = errror_msg || 'Parser Timeout ' where status > 2000 and spider_id = ? and ts_update <= ?", spider_id, tsUpdate)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Select 插入数据
|
||||
func (logdb *LogDB) Select(query string, args ...interface{}) *sql.Rows {
|
||||
Rows, err := logdb.driver.Query(query, args...)
|
||||
|
@ -110,7 +160,7 @@ func (logdb *LogDB) Select(query string, args ...interface{}) *sql.Rows {
|
|||
|
||||
// ADError 广告错误后更新
|
||||
func (logdb *LogDB) ADError(uid, error_msg string) {
|
||||
_, err := logdb.driver.Exec("update log_spider set status = status + 1000, error_msg=? where uid =?;", logdb.DB, error_msg, uid)
|
||||
_, err := logdb.driver.Exec("update log_spider set status = 1000, error_msg=? where uid =?;", logdb.DB, error_msg, uid)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user