fix some error

This commit is contained in:
pengtao 2019-07-16 10:08:03 +08:00
parent aca1272d4c
commit eea8f3c9b3

View File

@ -23,7 +23,7 @@ END = '3000-01-01'
def send_cache_data():
now = datetime.datetime.today().strftime("%Y-%m-%d")
now = datetime.datetime.today().strftime("%Y-%m-%d %H:%M%S")
all = []
# 添加无天数限定的记录
get_full_data = f"select id,name,ad_num,ad_title,ad_body,ad_image,ad_url,ad_sort,companyid,locationid,gameid from ad where begin_time='{BEGIN}' or end_time='{END}'"
@ -76,9 +76,23 @@ def send_cache_data():
if not my_redis.exists(f"{line['id']}::info"):
my_redis.hmset(f"{line['id']}::info", line)
len_all = len(all)
log.info(f"write {len_all} to cache!")
remove_expire_data()
def remove_expire_data():
now = datetime.datetime.today().strftime("%Y-%m-%d %H:%M%S")
sql = f"select id,gameid,locationid from ad where {now}>=end_time"
data = mydb.query(sql)
if data:
for line in data:
try:
id, gameid, locationid = line
my_redis.srem(f"{gameid}::{locationid}", id)
log.info(f"remove expire ad {id}!")
except Exception:
log.error("split data from db failed!", exc_info=True)
class DispatchHandler(tornado.web.RequestHandler):