def login(): ''' login method ''' login_form = LoginForm() rsyslog.send(u'login request(%s,%s,%s)' % (login_form.alias.data, login_form.password.data, datetime.now()), tag='login') try: if login_form.validate(): res = _login(login_form.alias.data, login_form.password.data, True) sentry.captureMessage('Login Result', extra={'result': res, 'alias': login_form.alias.data}) rsyslog.send(u'login result --- (%s,%s,%s)' % (login_form.alias.data, res, datetime.now()), tag='login') if errors.err_ok == res: return '', 204 else: return jsonify(errors=[{ 'message': login_err_msg_dict[res]}]), 403 sentry.captureMessage(login_form.failure, extra={'alias': login_form.alias}) return jsonify(errors=login_form.failure), 400 except Exception as ex: sentry.captureException(ex, extra={'id': login_form.alias, 'pass': '******'}) rsyslog.send(u'login error --- (%s,%s,%s)' % (login_form.alias.data, ex.message, datetime.now()), tag='login') return jsonify(errors=ex.message), 500
def consume(self): broker = self.get_broker() job = broker.reserve() if job is None: return bcolors.success('Get job %s' % job.jid) self._send_log('get job %s' % job.jid) try: self.target(job.body) except KeyboardInterrupt: job.bury() raise except WorkerTaskError: sentry.captureException(level=logging.WARNING) job.bury() except Exception as e: sentry.captureException() bcolors.fail('job %s failed and bury. %s' % (job.jid, unicode(e).encode('utf-8'))) self._send_log('job %s failed and buried because %s' % (job.jid, unicode(e).encode('utf-8'))) job.bury() else: bcolors.success('Job process success.') job.delete() self._send_log('job %s deleted' % job.jid)
def fetch_loans_digest(asset): try: data = xinmi.get_creditor_rights(order_id=asset.order_code) except BusinessError: sentry.captureException() raise FetchLoansDigestError() else: return XMLoansDigest.create_or_update(asset, data)
def fetch_loans_digest(asset): zhiwang_account = ZhiwangAccount.get_by_local(asset.user_id) try: data = zhiwang.client.asset_invest_info(zhiwang_account.zhiwang_id, asset.asset_no) except RemoteError: sentry.captureException() raise FetchLoansDigestError() else: return ZhiwangLoansDigest.create_or_update(asset, data)
def cancel_order(order_code): """取消订单""" try: # 调用第三方接口取消订单 result = xinmi.cancel(order_code) if result: if result.order_status is OrderStatus.user_cancel: order = XMOrder.get_by_order_code(order_code) if order: order.status = XMOrder.MUTUAL_STATUS_MAP[ result.order_status] except BusinessError: sentry.captureException()
def cancel_order(order_code): """取消订单""" try: # 调用第三方接口取消订单 result = sxb.cancel_order(order_code) if result: if result.order_status is OrderStatus.user_cancel: order = HoarderOrder.get_by_order_code(order_code) if order: order.update_by_remote_status(result.order_status) return True except BusinessError: sentry.captureException() return False
def notifications_multicast_push(multicast_info): """通知(Notification)面向用户群的组播 """ from core.models.pusher import PushController from core.models.pusher.element.audience import MultiUsersAudience from core.models.notification import NotificationKind notification_kind_id, user_ids = multicast_info.split(':') audience = MultiUsersAudience(user_ids.split(',')) notification_kind = NotificationKind.get(notification_kind_id) # 鉴于群体推送业务的特殊性,与其worker因为服务出错重新启动向用户发送多次 # 过时通知,不如在发生服务请求错误时忽略 try: PushController.multicast(notification_kind, audience=audience) except TException: sentry.captureException(**locals())
def pay_order(order, pay_code, sms_code): """发起支付""" # 对订单涉及到的礼券、抵扣优惠开启业务排斥锁 order.lock_bonus() # 更新订单状态为已请求并为支付开启事务排斥锁 # order.update_status(ZhiwangOrder.Status.committed) try: # 调用第三方接口发起支付 zhiwang.order_pay( ZhiwangAccount.get_by_local(order.user_id).zhiwang_id, # 用户指旺ID order.order_code, # 订单流水号 order.pay_code, # 订单支付单号 sms_code, # 手机验证码 order.pay_amount # 实际支付金额 ) except RemoteError as e: status, msg = e.args if status == 'pay_wait': # 订单支付仍在进行,订单、优惠、礼券依旧被冻结 order.update_status(ZhiwangOrder.Status.paying) elif status == 'pay_success_before': # 支付被告知已成功过,前往结束页 pass else: # 释放被冻结的礼券、抵扣金 order.unlock_bonus() # FIXME(Justin) 太暴力,需要改进, if status == 'pay_verify_code_wrong' and msg == u'错误次数太多,请明日再试': # 订单失败时会接收到信号来unlock bonus, 所以先lock bonus order.lock_bonus() order.update_status(ZhiwangOrder.Status.failure) else: raise PayTerminatedError(u'支付执行失败: %s' % msg) except (ConnectionError, HTTPError, ReadTimeout): # 支付接口超时或其他网络错误,mq追踪状态 sentry.captureException() order.track_for_payment() else: # 支付成功 order.update_status(ZhiwangOrder.Status.success)
def synchronize_asset(self, asset_code, raises=False): # 资产可能变动的属性:状态,当前资产金额,当前利息,回款银行卡(用户线下变更) if not self.zhiwang_account: return asset = ZhiwangAsset.get_by_asset_no(asset_code) if not asset or asset.user_id != self.account_id: return try: detail = zhiwang.asset_details(self.zhiwang_account.zhiwang_id, asset_code) except (RemoteError, RequestException): if raises: raise if current_app: sentry.captureException() return status = ZhiwangAsset.MUTUAL_STATUS_MAP.get(detail.status) asset.synchronize(status, detail.current_amount, detail.current_interest, detail.user_bank_account)
def handle_coupon_error(self, error): sentry.captureException() return jsonify(success=False, messages={'_': [error.args[0]]}), 403