def init(): logger.warning('Init accounts pool...') rh.del_queue(config('queue.admin_acct')) with open(all_acct_file, 'r') as f: while True: line = f.readline() if not line: break else: acct = line.strip().split(' ') acct_dict = {'username': acct[0], 'password': acct[1]} rh.push_acct(acct_dict)
def get(*old): global using if config('env') == 'dev': return { 'username': '******', 'password': '******' } if old: rh.push_acct(old[0]) new_acct = rh.get_acct() logger.warning('Get new account %s from master', new_acct['username']) using = new_acct return new_acct
def terminate(*msg): if msg: logger.error(msg[0]) status.update({ 'status': 'error', 'message': str(msg[0]) }) else: status.update({ 'status': 'exit', 'message': 'Exit gracefully', }) logger.error('Terminate gracefully...') acct = Account.get_using() if 'username' in acct: rh.push_acct(acct) logger.error('return account %s', acct['username']) if task: rh.lpush_task_user(task) logger.error('return task %s', task) status.update({ 'finished': finished, 'task': task, 'account': acct, 'update_time': int(time.time()) }) rh.publish_status(status) logger.error('Exit') if msg: sys.exit(msg[0]) else: sys.exit(0)