def get_deal_result(self, auth_info, data):
        """
         获取处理结果信息,设定总共等待31倍time_sleep时长检查请求是否处理完成(本例等待 31*10=310 秒)
        超过等待时长则设为处理超时
        """
        get_result_public = Feeds(auth_info['AWSAccessKeyId'],
                                  auth_info['SecretKey'],
                                  auth_info['SellerId'], auth_info['ShopSite'])
        feed_id = data['FeedSubmissionInfo']['FeedSubmissionId']['value']

        print '\n'
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
        print 'result id is: %s, now wait for  10 seconds  then check deal status.' % feed_id
        logging.debug(
            'result id is: %s, now wait for  10 seconds  then check deal status.'
            % feed_id)

        time_sleep = 10
        count = 0
        while count < 5:
            time.sleep(time_sleep)
            time_sleep += time_sleep  # 每次等待时长翻倍(即10,20,40,80,160)
            count += 1
            try:
                feed_processing_status = self.get_deal_status(
                    auth_info, feed_id)
                if feed_processing_status == '_DONE_':
                    print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                    print 'now we can get the result'
                    logging.debug('now we can get the result')
                    feed_result = get_result_public.get_feed_submission_result(
                        feed_id)
                    print 'get result raw'
                    logging.debug('get result raw')
                    response = feed_result._response_dict
                    print 'get result dict'
                    logging.debug('get result dict: %s' % str(response))
                    print response
                    return response
                else:
                    print '\n'
                    print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                    print 'processing_status is:%s, we will wait for %s seconds ' % (
                        feed_processing_status, time_sleep)
                    logging.debug(
                        'processing_status is:%s, we will wait for %s seconds '
                        % (feed_processing_status, time_sleep))
            except Exception as e:
                print datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
                print 'error: %s' % e
                logging.error('error: %s' % e)
        else:  # 循环超过5次,即总等待时长超过 31*time_sleep,则计为超时
            print 'Get submit_feed reuslt timeout'
            logging.error('Get submit_feed reuslt timeout')
            return None
Example #2
0
 def getsubmitfeedresult(self, auth_info, data):
     '''
     _POST_PRODUCT_DATA_:
         {
             'Header': {
                 'MerchantIdentifier': {
                     'value': 'A3E57KPT99E29C'
                 },
                 'DocumentVersion': {'value': '1.02'},
                 'value': '\n\t\t'
             },
             'Message': {
                 'ProcessingReport': {
                     'DocumentTransactionID': {'value': '57844017533'},
                     'ProcessingSummary': {
                         'MessagesProcessed': {'value': '4'},
                         'MessagesWithWarning': {'value': '0'},
                         'MessagesSuccessful': {'value': '4'},
                         'value': '\n\t\t\t\t',
                         'MessagesWithError': {'value': '0'}
                     },
                     'value': '\n\t\t\t',
                     'StatusCode': {'value': 'Complete'}
                 },
                 'value': '\n\t\t',
                 'MessageID': {'value': '1'}
             },
             'noNamespaceSchemaLocation': {
                 'namespace': 'http://www.w3.org/2001/XMLSchema-instance',
                 'value': 'amzn-envelope.xsd'
             },
             'MessageType': {'value': 'ProcessingReport'},
             'value': '\n\t'
         }
     '''
     time.sleep(60)
     region = auth_info['ShopName'].split('/')[0].split('-')[-1]
     submitfeed = Feeds(auth_info['AWSAccessKeyId'], auth_info['SecretKey'], auth_info['SellerId'], region=region)
     feedid = data['FeedSubmissionInfo']['FeedSubmissionId']['value']
     time_sleep = 10
     count = 0
     while True:
         time.sleep(time_sleep)
         time_sleep += time_sleep
         count += 1
         try:
             feedresult = submitfeed.get_feed_submission_result(feedid)
             response = feedresult._response_dict
             if response.get('Message') and \
                     response.get('Message').get('ProcessingReport') and \
                     response.get('Message').get('ProcessingReport').get('StatusCode') and \
                     response.get('Message').get('ProcessingReport').get('StatusCode').get('value'):
                 logger.debug('Get submitfeed result: %s' % response)
                 return response
             # else:
             #     logger.debug('Have got submitfeed result but not complete: %s' % response)
         except Exception as e:
             print 'error: %s' % e
             logger.error('error: %s' % e)
         if count < 7:
             continue
         else:
             # return {'error': 'Get submitfeed reuslt timeout', 'code': 408}
             return {}