def monitor_download_status(): redis_queue = RedisMsgQueue() while True: all_files_old_json = redis_queue.hash_get_all( consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME) for hash_sign in all_files_old_json.keys(): all_files_old_json[hash_sign] = from_string_to_json( all_files_old_json[hash_sign]) all_files_old_json[hash_sign]['now_size'] = get_file_size( all_files_old_json[hash_sign]['absolute_path']) time.sleep(10) # 5分钟下载中文件大小不变化,认为下载服务异常挂掉,删除下载队列 all_files_new_json = redis_queue.hash_get_all( consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME) for hash_sign in all_files_new_json: all_files_new_json[hash_sign] = from_string_to_json( all_files_new_json[hash_sign]) all_files_new_json[hash_sign]['now_size'] = get_file_size( all_files_new_json[hash_sign]['absolute_path']) if int(all_files_new_json[hash_sign]['now_size']) - int( all_files_old_json[hash_sign]['now_size']) == 0: redis_queue.hash_del( consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME, hash_sign) logging.debug('monitor download queue') pass
def downloading_status_manager(self): if self.status == consts.constant_manager.DOWNLOADING: download_file_status_json = copy.deepcopy( tmp_download_file_status_json) download_file_status_json['hash_sign'] = self.hash_sign download_file_status_json['absolute_path'] = self.title download_file_status_json['total_size'] = self.total download_file_status_json['now_size'] = self.now_size download_file_status_json['download_speed'] = self.speed download_file_status_json['status'] = self.status scheduler_download_status_queue(download_file_status_json) elif self.status == consts.constant_manager.DOWNLOAD_OVER: redis_queue = RedisMsgQueue() redis_queue.hash_del( consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME, self.hash_sign)
def demo_queue(): redis_queue = RedisMsgQueue() aa = redis_queue.hash_del( consts.constant_manager.DOWNLOAD_STATUS_QUEUE_NAME, '748ffc2387967c2d0ec518516239ea42') pass