import time from libs.db_mysql import DbMysql class MysqlLiveReplay(DbMysql): table = 'live_replay' # 判断任务是否为重试任务 def is_retry_task(self, task_id): sql = 'SELECT * FROM ' + self.table + ' WHERE `id`=%s AND `status`=%s' try: # 执行SQL self.cursor.execute(sql, [task_id, '3']) return self.cursor.fetchone() finally: self.db.commit() # 提交 self.cursor.close() # 关闭cursor self.db.close() # 关闭db连接 # 设置下载任务开始状态 def set_task_begin(self, task_id, status): sql = 'UPDATE ' + self.table + ' SET `status`=%s, `download_begin_at`=%s WHERE `id`=%s' try: # 执行SQL result = self.cursor.execute(sql, [status, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()), task_id]) return result finally: self.db.commit() # 提交 self.cursor.close() # 关闭cursor self.db.close() # 关闭db连接 # 修改下载任务状态 def set_task_status(self, task_id, status): sql = 'UPDATE ' + self.table + ' SET `status`=%s WHERE `id`=%s' try: # 执行SQL result = self.cursor.execute(sql, [status, task_id]) return result finally: self.db.commit() # 提交 self.cursor.close() # 关闭cursor self.db.close() # 关闭db连接 # 设置回放地址 def set_video_url(self, task_id, url): current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) sql = 'UPDATE ' + self.table + ' SET `status`=2,video_url=%s,download_finish_at=%s WHERE `id`=%s' try: # 执行SQL result = self.cursor.execute(sql, [url, current_time, task_id]) return result finally: self.db.commit() # 提交 self.cursor.close() # 关闭cursor self.db.close() # 关闭db连接 # 获取需要上传的直播信息 def get_replay_upload_info(self): last_download_at = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()) - 3600)) sql = 'SELECT id,live_id FROM ' + self.table + ' WHERE `status`=5 LIMIT 1' try: # 执行SQL self.cursor.execute(sql) return self.cursor.fetchone() finally: self.db.commit() # 提交 self.cursor.close() # 关闭cursor self.db.close() # 关闭db连接