def clean_notice(): """ 清除通知管理数据 :return: """ mysql_execute('truncate tbl_trade_notice',trade=True) redis_execute().delete('netCar:NOTICE_REDIS_CACHE_KEY:')
def clean_activity_rule(): """ 清除活动细则 :return: """ mysql_execute('truncate tbl_trade_activity_rules_config',trade=True) redis_execute().delete('netCar:IMAGE_CACHE_KEY:1') redis_execute().delete('netCar:IMAGE_CACHE_KEY:2')
def delete_image(): """ 删除图片 :return: """ mysql_execute('delete from tbl_trade_image',trade=True) redis_execute(trade=True).delete('netCar:IMAGE_CACHE_KEY')
def delete_activity_display(): """ 删除活动展示管理数据 :param activity_display_id: :return: """ mysql_execute('TRUNCATE `netCar`.`tbl_trade_activity_display_manage`',trade=True) redis_execute().delete('netCar:ACTIVITY_DISPLAY_MANAGE_KEY:')
def fix_random_activity_use_num(activity_id,type,number): """ 修改随机立减活动使用数量 :param activity_id: :return: """ if type == 'cycle': redis_execute(trade=True).set(name='netCar:ACTIVITY:ACTIVITY_ID_CYCLE_{0}'.format(activity_id),value=number) else: redis_execute(trade=True).set(name='netCar:ACTIVITY:ACTIVITY_ID_{0}'.format(activity_id),value=number)
def spdb_test_helper(request): """ Spdb测试辅助 :param request: :param id: str or int:当前页 :return: """ account = request.session["now_account"] # 查询订单支付轮循状态 round_flag = False run_detail = os.popen( 'ps -ef | grep spdb_pay_round | grep -v grep').readlines() logger.info('Query Spdb order round-robin task: {0}'.format(run_detail)) if run_detail: round_flag = True max_times = redis_helper.redis_execute().get( name=redis_helper.SPDB_PAYCB_ROUNT_MAX_NUMBER_KEY) logger.info('Maximum number of rotation: {0}'.format(max_times)) current_times = redis_helper.redis_execute().get( name=redis_helper.SPDB_PAYCB_ROUNT_CURRENT_NUMBER_KEY) logger.info('Current cycle times: {0}'.format(current_times)) progress = 0 if max_times and current_times: progress = int(int(current_times) / int(max_times) * 100) logger.info('The current progress: {0}'.format(progress)) flag = False # 查询全员免密状态 secret_state = redis_helper.redis_execute(trade=True).get( name='netcar:secretState:') if secret_state == None: secret_state = True else: if int(str(secret_state, 'utf-8')) == 1: flag = True else: flag = False logger.info( 'At present, all employees are exempt from confidentiality: {0}'. format(secret_state)) manage_info = { 'account': account, 'round_task': { 'name': 'Spdb订单支付轮循', 'enabled': round_flag, 'progress': progress }, 'secret_task': { 'name': 'Spdb全员免密开关', 'enabled': flag } } return render_to_response('spdb_test_helper.html', manage_info)
def sz_callback_accepted(self): """ 神州订单回调接单 :param request: :return: """ # 查询渠道ID与pipe_id car_info_detail = mysql_execute( 'select * from netCarPlatform.tbl_platform_car_info where trade_order_id=%s and channel_type=4 limit 1', params=(self.trade_order_id)) if not car_info_detail: return '未查询到该订单!' channel_order_id = car_info_detail['channel_order_id'] # 渠道ID partner_order_id = car_info_detail['id'] # 定义请求参数 change_status_request_data = { "bankFlag": 1, "content": { "dOrderId": partner_order_id, "eventExplanation": "", "orderId": channel_order_id, "status": 'dispatched' }, "operation": "statusChanged" } # 更新订单详情接口返回数据 default_data = json.loads( mysql_execute( 'select api_response from mock_response where api_url="/v1/resource/order/getOrderDetail" and channel="sz"', platform=True)['api_response']) default_data['content']['order']['id'] = channel_order_id default_data['content']['order']['customData'] = json.dumps( {"dOrderId": partner_order_id}) default_data['content']['order']['status'] = 'dispatched' redis_execute().set(name=str(channel_order_id) + '_sz_order_detail_response', value=json.dumps(default_data)) logger.info('redis key: {0}'.format( str(channel_order_id) + '_sz_order_detail_response')) logger.info('redis value: {0}'.format(json.dumps(default_data))) logger.info('update redis success!') # 请求参数加密 request_encrypt = requests.get( url=self.sz_encrypt_url, params={'q': str(change_status_request_data)}, headers=self.headers) logger.info('sz request encrypt url: {0}'.format(self.sz_encrypt_url)) logger.info( 'sz request encrypt data: {0}'.format(change_status_request_data)) logger.info(request_encrypt.text) return {'request_data': {'q': request_encrypt.text}}
def delete_activity(activity_id,sign_id): """ 删除活动 :param activity_id: :param status: :return: """ detail = mysql_execute('select * from tbl_trade_activity where activity_id=%s',params=(activity_id),trade=True) if detail: redis_execute(trade=True).delete('netCar:ACTIVITY:ACTIVITY_ID_{0}'.format(detail['id'])) mysql_execute('delete from tbl_trade_activity where activity_id=%s',params=(activity_id),trade=True) redis_execute(trade=True).delete('netCar:ACTIVITY:ACTIVITY_INFO') mysql_execute('delete from tbl_trade_activity_config where sign_id=%s',params=(sign_id),trade=True) mysql_execute('delete from tbl_trade_activity_detail where activity_id=%s',params=(activity_id),trade=True) mysql_execute('delete from tbl_trade_activity_customer_relation where activity_id=%s',params=(activity_id),trade=True) mysql_execute('delete from tbl_trade_activity_customer_record where activity_id=%s',params=(activity_id),trade=True) mysql_execute('delete from tbl_trade_coupon_recharge_record where activity_id=%s',params=(activity_id),trade=True)
def query_ps_and_redis(monitoring_file_name): """ 查询进程状态与Redis结果数据 :param monitoring_file_name: :return: """ running_flag = '未启动' # 查询该任务是否正在运行 run_detail = os.popen('ps -ef | grep %s | grep -v grep' % monitoring_file_name).readlines() logger.info('Query Spdb {0} task: {1}'.format(monitoring_file_name, run_detail)) if run_detail: running_flag = '运行中' else: # 查询该任务是都在待执行列表中 redis_value = redis_helper.redis_execute().get( redis_helper.TEST_SUITE_KEY) if redis_value: down_job_detail = json.loads(redis_value) down_job_list = down_job_detail['down_job_list'] if monitoring_file_name in str(down_job_list): running_flag = '等待中' run_result_flag = True result_format = { 'monitoring_name': None, 'run_time': None, 'running_time': None, 'time_diff': None } run_result = redis_helper.redis_execute().get( name=monitoring_file_name) result_info = [] if run_result: result_format = json.loads(run_result) for x in result_format['result']: if x['result'] != True: run_result_flag = False result_info.append({ "method_name": x['method'], 'message': x['message'] }) # 获取近10次执行结果通过率 run_success_percent_last_ten = 0 last_ten_run_details = mysql_execute( 'select * from test_http.pf_monitoring where redis_key=%s order by create_time desc limit 10', params=(monitoring_file_name), platform=True, is_fetchone=False) run_list = [] if last_ten_run_details: for i in last_ten_run_details: run_list.append(int(i['result'])) success_num = run_list.count(0) run_success_percent_last_ten = int( int(success_num) / len(last_ten_run_details) * 100) # 获取全部执行结果通过率 all_run_success_percent = 0 all_run_details = mysql_execute( 'select * from test_http.pf_monitoring where redis_key=%s', params=(monitoring_file_name), platform=True, is_fetchone=False) all_run_list = [] if all_run_details: for i in all_run_details: all_run_list.append(int(i['result'])) all_success_num = all_run_list.count(0) all_run_success_percent = int( int(all_success_num) / len(all_run_details) * 100) result_list.append({ 'name': result_format['monitoring_name'], 'last_ten_success_percent': run_success_percent_last_ten, 'all_success_percent': all_run_success_percent, 'enabled': running_flag, 'status': run_result_flag, 'message': result_info, 'run_time': result_format['run_time'], 'running_time': result_format['running_time'], 'monitoring_name': monitoring_file_name, 'time_diff': result_format['time_diff'] })
def start_or_stop_monitoring(request): """ 场景监控开启、关闭 :param request: :param id: str or int:当前页 :return: """ if request.is_ajax(): kwargs = json.loads(request.body.decode('utf-8')) mode = kwargs['mode'] monitoring_name = kwargs['monitoring_name'] logger.info('params mode: {0}'.format(mode)) logger.info('monitoring name:{0}'.format(monitoring_name)) if mode == True: if monitoring_name == 'all': all_key = redis_helper.KEY_LIST logger.info('all monitoring key:{0}'.format(all_key)) # 过滤掉当前正在执行的任务,将待执行的任务名称加入list down_job_list = [] for x in all_key: run_detail = os.popen( 'ps -ef | grep {0} | grep -v grep'.format( x)).readlines() if not run_detail: down_job_list.append({ 'monitoring_name': x, 'status_desc': '等待中', 'join_time': time.time() }) # 将待执行任务添加到redis logger.info('Inhale the queue to be executed!') logger.info('down job list : {0}'.format(down_job_list)) value = {'down_job_list': down_job_list} redis_helper.redis_execute().set(redis_helper.TEST_SUITE_KEY, json.dumps(value)) logger.info('Store successful!') return HttpResponse('ok') else: run_detail = os.popen( 'ps -ef | grep {0} | grep -v grep'.format( monitoring_name)).readlines() if run_detail: return HttpResponse('正在运行中!') # 获取待执行列表 down_job_detail = json.loads(redis_helper.redis_execute().get( redis_helper.TEST_SUITE_KEY)) down_job_list = down_job_detail['down_job_list'] logger.info('down job list:{0}'.format(down_job_detail)) # 判断该任务是否在待执行列表中 if monitoring_name in str(down_job_list): return HttpResponse('已在待执行队列中,请等待!') else: down_job_detail['down_job_list'].append({ 'monitoring_name': monitoring_name, 'status_desc': '等待中', 'join_time': time.time() }) redis_helper.redis_execute().set( redis_helper.TEST_SUITE_KEY, json.dumps(down_job_detail)) logger.info('Update successful!') logger.info('down job list:{0}'.format(down_job_detail)) return HttpResponse('ok') elif mode == False: if monitoring_name == 'all': # 获取待执行任务列表 down_job_detail = json.loads(redis_helper.redis_execute().get( redis_helper.TEST_SUITE_KEY)) down_job_detail['down_job_list'] = [] redis_helper.redis_execute().set(redis_helper.TEST_SUITE_KEY, json.dumps(down_job_detail)) logger.info('Update successful!') logger.info('down job list:{0}'.format(down_job_detail)) return HttpResponse('ok') else: # monitoring_name = 'monitoring' # logger.info('Query Spdb {0}!'.format(monitoring_name)) # pids = os.popen("ps -ef | grep %s | grep -v grep | awk '{print $2}'" % monitoring_name) # if pids: # return HttpResponse('正在运行,请等待执行完成!') down_job_detail = json.loads(redis_helper.redis_execute().get( redis_helper.TEST_SUITE_KEY)) down_job_list = down_job_detail['down_job_list'] logger.info('down job list:{0}'.format(down_job_detail)) for x in down_job_list: # 判断该任务是否在待执行列表中,如果存在则在列表中删除 if monitoring_name == x['monitoring_name']: down_job_list.remove(x) redis_helper.redis_execute().set( redis_helper.TEST_SUITE_KEY, json.dumps(down_job_detail)) logger.info('Update successful!') logger.info( 'down job list:{0}'.format(down_job_detail)) return HttpResponse('ok') return HttpResponse('ok') else: return HttpResponse('请求方式错误!')
# -*- coding:utf-8 -*- from HttpRunnerManager import settings from ApiManager.utils.mysql_helper import mysql_execute import time, requests from ApiManager.utils import redis_helper if __name__ == '__main__': max_count = 2000 count = 1 redis_helper.redis_execute().set( name=redis_helper.SPDB_PAYCB_ROUNT_MAX_NUMBER_KEY, value=max_count) while count < max_count: redis_helper.redis_execute().set( name=redis_helper.SPDB_PAYCB_ROUNT_CURRENT_NUMBER_KEY, value=count) orders = mysql_execute( 'select * from tbl_trade_order where order_status in (22,25)', is_fetchone=False, trade=True) if orders: print('Paying order number: {0}'.format(len(orders))) for x in orders: order_id = x['id'] print('Start order id: {0}'.format(order_id)) order_pay_record_detail = mysql_execute( 'select id from tbl_trade_order_pay_record where order_id=%s', params=(order_id), trade=True) pay_record_id = order_pay_record_detail['id'] request_data = { "data": {
).click() #停止接单 self.find_element_by( By.XPATH, '/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout[2]/android.widget.TextView[2]' ).click() return True except: return False if __name__ == '__main__': caocao = CaoCaoDriver() while True: result = None command = redis_execute().get(name=CAOCAO_DRIVER_COMMAND) if command: command_format = json.loads(command) event = command_format['event'] event_status = command_format['status'] if int(event_status) == 0: logger.info('New Command:{0}'.format(command_format)) if event == 'down': result = caocao.driver_down() elif event == 'dispatched': caocao.driver_online() result = caocao.start_service() elif event == 'arrived': result = caocao.update_order_status() elif event == 'serviceStarted': result = caocao.update_order_status()