def main(): load_argvs() CommonLog.print_welcome() # 初始化配置 App.run() CommonLog.print_configs() # 加载站点信息 App.did_start() #print('App.did_start() done.') # 检查运行环境的相关目录以及验证码校验的api用户名密码设置是否正确 App.run_check() #print('App.run_check() done') # 初始化查询任务,获取余票查询url Query.check_before_run() #print('Query.check_before_run() done') ####### 运行任务 Web.run() Cdn.run() #12306账号登录 User.run() Query.run() if not Const.IS_TEST: while True: sleep(10000) else: if Config().is_cluster_enabled(): stay_second(5) # 等待接受完通知 CommonLog.print_test_complete()
def destroy(self): """ 退出任务 :return: """ from py12306.query.query import Query self.is_alive = False QueryLog.add_quick_log(QueryLog.MESSAGE_QUERY_JOB_BEING_DESTROY.format(self.job_name)).flush() # sys.exit(1) # 无法退出线程... # 手动移出jobs 防止单线程死循环 index = Query().jobs.index(self) Query().jobs.pop(index)
def main(): if '--test' in sys.argv or '-t' in sys.argv: test() CommonLog.print_welcome().print_configs() App.run_check() User.run() Query.run() if not Const.IS_TEST: while True: sleep(10000) CommonLog.print_test_complete()
def update_configs_from_remote(self, envs, first=False): if envs == self.envs: return from py12306.query.query import Query from py12306.user.user import User for key, value in envs: if key in self.disallow_update_configs: continue if value != -1: old = getattr(self, key) setattr(self, key, value) if not first: if key == 'USER_ACCOUNTS' and old != value: User().update_user_accounts(auto=True, old=old) elif key == 'QUERY_JOBS' and old != value: Query().update_query_jobs(auto=True) # 任务修改 elif key == 'QUERY_INTERVAL' and old != value: Query().update_query_interval(auto=True)
def main(): load_argvs() CommonLog.print_welcome() App.run() CommonLog.print_configs() App.did_start() App.run_check() User.run() Query.run() if not Const.IS_TEST: while True: sleep(10000) else: if Config().is_cluster_enabled(): stay_second(5) # 等待接受完通知 CommonLog.print_test_complete()
def query_lists(): """ 查询任务列表 :return: """ jobs = Query().jobs result = list(map(convert_job_to_info, jobs)) return jsonify(result)
def job_destroy(self, data={}, callback=False): # 停止查询任务 from py12306.query.query import Query if Config().is_cluster_enabled() and not callback: return self.cluster.publish_event(self.KEY_JOB_DESTROY, data) # 通知其它节点退出 job = Query.job_by_name(data.get('name')) if job: job.destroy()
def user_loaded(self, data={}, callback=False): # 用户初始化完成 if Config().is_cluster_enabled() and not callback: return self.cluster.publish_event(self.KEY_USER_LOADED, data) # 通知其它节点退出 from py12306.query.query import Query if not Config().is_cluster_enabled() or Config().is_master(): query = Query.wait_for_ready() for job in query.jobs: if job.account_key == data.get('key'): create_thread_and_run(job, 'check_passengers', Const.IS_TEST) # 检查乘客信息 防止提交订单时才检查
def dashboard(): """ 状态统计 任务数量,用户数量,查询次数 节点信息(TODO) :return: """ from py12306.log.query_log import QueryLog query_job_count = len(Query().jobs) user_job_count = len(User().users) query_count = QueryLog().data.get('query_count') return jsonify({ 'query_job_count': query_job_count, 'user_job_count': user_job_count, 'query_count': query_count })
def dashboard(): """ 状态统计 任务数量,用户数量,查询次数 节点信息(TODO) :return: """ from py12306.log.query_log import QueryLog query_job_count = len(Query().jobs) user_job_count = len(User().users) query_count = QueryLog().data.get('query_count') res = { 'query_job_count': query_job_count, 'user_job_count': user_job_count, 'query_count': query_count, } if Config().CDN_ENABLED: from py12306.helpers.cdn import Cdn res['cdn_count'] = len(Cdn().available_items) return jsonify(res)