diff --git a/logdb.go b/logdb.go index fd34a71..86d6091 100644 --- a/logdb.go +++ b/logdb.go @@ -100,9 +100,10 @@ func (logdb *LogDB) Connect() { // ADInsert 插入数据 func (logdb *LogDB) ADInsert(uid, device, platform, area_cc, section_id, response string, spider_id, channel, media, catch_account_id, status, priority int, ts_crawl time.Time) { - _, err := logdb.driver.Exec("insert into log_spider (uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, error_msg, status, priority, ts_crawl) value(?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ? ,?, ?, ?)", uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, "", status, priority, ts_crawl) + _, err := logdb.driver.Exec("insert into log_spider (uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, error_msg, status, priority, ts_crawl) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ? , ? ,?, ?, ?)", uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, "", status, priority, ts_crawl) if err != nil { log.Println(err) + log.Printf("for save ad sql: insert into log_spider (uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, error_msg, status, priority, ts_crawl) values(%s, %s, %s, %s, %d, %d, %s, %d, %s, %s, %s, %d, %d, %s)\n", uid, spider_id, device, platform, channel, media, area_cc, catch_account_id, section_id, response, "", status, priority, ts_crawl.Format("2006-01-02 15:04:05")) } } @@ -119,11 +120,13 @@ func (logdb *LogDB) ADParserSelect(spider_id int) []ADResonse { _, 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) + return nil } 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) + return nil } var adresponse []ADResonse @@ -144,7 +147,7 @@ func (logdb *LogDB) ADCheckError(spider_id int) { 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) + _, err := logdb.driver.Exec("update log_spider set status = 0, error_msg = CONCAT(error_msg, 'Parser Timeout ') where status > 2000 and spider_id = ? and ts_update <= ?", spider_id, tsUpdate) if err != nil { log.Println(err) } @@ -156,13 +159,14 @@ func (logdb *LogDB) Select(query string, args ...interface{}) *sql.Rows { Rows, err := logdb.driver.Query(query, args...) if err != nil { log.Println(err) + return nil } return Rows } // ADError 广告错误后更新 func (logdb *LogDB) ADError(uid, error_msg string) { - _, err := logdb.driver.Exec("update log_spider set 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 =?;", error_msg, uid) if err != nil { log.Println(err) }