backup_reporter.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:nc-backup-py 作者: ChinaNetCloud 项目源码 文件源码
def send_post_report(self):
        """Send post report to a given URL."""
        data_post = self.create_post_report()
        count = 1
        time_retry = 60
        message_config_command = self.__json_dict['GENERAL']['MESSAGE_CONFIG_COMMAND']
        message_config_method = self.__json_dict['GENERAL']['MESSAGE_CONFIG_METHOD']
        while count <= 5:
            request_to_brt = Communications.send_message(
                Communications(),
                data_post,
                message_config_command,
                message_config_method)
            self.__logger.info(
                'Report sent status: ' +
                str(request_to_brt.status_code) +
                ' <===> ' + request_to_brt.reason)
            print 'Response from server:'
            attempt_notification = 'Attempt: ' + str(count)
            print attempt_notification
            self.__logger.info(attempt_notification)
            print (request_to_brt.status_code, request_to_brt.reason)
            self.__logger.info('Server response: ' + str(request_to_brt.status_code) + ' ' + str(request_to_brt.reason))
            # this should make the script wait for 60s (1min), 120s (2min), 360s (6min), 1440s (24min), 7200s (2h)
            time_retry = time_retry * count
            count = count + 1
            if request_to_brt.status_code == 200:
                self.__logger.info('Sent')
                break
            elif request_to_brt.status_code != 200 and count is not 5:
                attempt_failed_notification = 'The attempt to send report failed. Attempt number ' + \
                                              str(count) + ' will be in: ' + str(time_retry/60) + ' minutes.'
                print attempt_failed_notification
                self.__logger.warning(attempt_failed_notification)
                time.sleep(time_retry)
            elif count == 5 and request_to_brt.status_code != 200:
                attempt_failed_notification = 'Last attempt to send report FAILED, please check connectivity to BRT'
                print attempt_failed_notification
                self.__logger.critical(attempt_failed_notification)
                exit(1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号