def launch(cls): workdays = TradingPeriod.get_workdays(begin='2016-12-31', end='2019-12-31') workdays_exchange_trading_period_by_ts = \ TradingPeriod.get_workdays_exchange_trading_period( _workdays=workdays, exchange_trading_period=EXCHANGE_TRADING_PERIOD) while True: if Utils.exit_flag: msg = 'Thread DataArrangeEngine say bye-bye' print msg logger.info(msg=msg) return try: awp_tick = db.r.lpop(app.config['data_stream_queue']) if awp_tick is None: time.sleep(1) continue awp_tick = json.loads(awp_tick) # 过滤交易量为 0 的假数据 if 'volume' in awp_tick and awp_tick['volume'] == 0: continue contract_code = pattern.match( awp_tick['instrument_id']).group() action_day = awp_tick['action_day'] update_time = awp_tick['update_time'] # 时间合法性校验 if not trading_time_filter( date_time=' '.join([action_day, update_time]), contract_code=contract_code, exchange_trading_period_by_ts= workdays_exchange_trading_period_by_ts['-'.join([ action_day[:4], action_day[4:6], action_day[6:] ])]): continue cls.data_arrange(awp_tick=awp_tick) except AttributeError as e: logger.error(traceback.format_exc()) time.sleep(1) if db.r is None: db.init_conn_redis() except Exception as e: logger.error(traceback.format_exc()) time.sleep(1)
def launch(cls): logger.info(msg='Thread EventProcessor is launched.') while True: if Utils.exit_flag: msg = 'Thread EventProcessor say bye-bye' print msg logger.info(msg=msg) return try: report = db.r.lpop(app.config['upstream_queue']) if report is None: time.sleep(1) continue cls.message = json.loads(report) if cls.message['kind'] == EmitKind.log.value: cls.log_processor() elif cls.message['kind'] == EmitKind.guest_event.value: cls.guest_event_processor() elif cls.message['kind'] == EmitKind.host_event.value: cls.host_event_processor() elif cls.message['kind'] == EmitKind.response.value: cls.response_processor() elif cls.message[ 'kind'] == EmitKind.guest_collection_performance.value: cls.guest_collection_performance_processor() elif cls.message[ 'kind'] == EmitKind.host_collection_performance.value: cls.host_collection_performance_processor() else: pass except AttributeError as e: logger.error(traceback.format_exc()) time.sleep(1) if db.r is None: db.init_conn_redis() except Exception as e: logger.error(traceback.format_exc()) time.sleep(1)
action_day = awp_tick['action_day'] update_time = awp_tick['update_time'] # 时间合法性校验 if not trading_time_filter( date_time=' '.join([action_day, update_time]), contract_code=contract_code, exchange_trading_period_by_ts=workdays_exchange_trading_period_by_ts[ '-'.join([action_day[:4], action_day[4:6], action_day[6:]])]): continue cls.data_arrange(awp_tick=awp_tick) except AttributeError as e: logger.error(traceback.format_exc()) time.sleep(1) if db.r is None: db.init_conn_redis() except Exception as e: logger.error(traceback.format_exc()) time.sleep(1) if __name__ == '__main__': try: DataArrangeEngine.launch() except: logger.error(traceback.format_exc()) exit(-1)
def teardown_request(exception): if exception: _traceback = get_current_traceback() logger.error(_traceback.plaintext)