当前位置: 首页>>代码示例>>Python>>正文


Python LOG.error方法代码示例

本文整理汇总了Python中scalrpy.LOG.error方法的典型用法代码示例。如果您正苦于以下问题:Python LOG.error方法的具体用法?Python LOG.error怎么用?Python LOG.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scalrpy.LOG的用法示例。


在下文中一共展示了LOG.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_servers

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def get_servers(self, limit=500):
        for servers in self._get_servers(limit=limit):

            prop = ['scalarizr.api_port', 'scalarizr.key']
            self._db.load_server_properties(servers, prop)

            for server in servers:
                if 'scalarizr.api_port' not in server:
                    server['scalarizr.api_port'] = 8010
                if 'scalarizr.key' not in server:
                    server['scalarizr.key'] = None

            self._db.load_vpc_settings(servers)

            out = []
            for server in servers:
                try:
                    if server['os_type'] == 'linux':
                        exclude = ['snum']
                    elif server['os_type'] == 'windows':
                        exclude = ['la', 'io', 'snum']
                    else:
                        msg = "Wrong os type for server: '%s'" % server['server_id']
                        raise Exception(msg)
                    metrics = [m for m in self.config['metrics'] if m not in exclude]
                    server['metrics'] = metrics
                    out.append(server)
                except:
                    LOG.error(helper.exc_info())
                    continue
            yield out
开发者ID:afrank,项目名称:scalr,代码行数:33,代码来源:load_statistics.py

示例2: _serve_forever

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
 def _serve_forever(self):
     LOG.debug('Starting plotter')
     try:
         cherrypy.quickstart(self, '/', {'/': {}})
     except:
         LOG.error(helper.exc_info())
         thread.interrupt_main()
开发者ID:afrank,项目名称:scalr,代码行数:9,代码来源:load_statistics.py

示例3: _handle_webhook_exception

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
 def _handle_webhook_exception(self, webhook):
     exc = sys.exc_info()[1]
     if isinstance(exc, (
             requests.exceptions.Timeout,
             requests.exceptions.ProxyError,
             requests.exceptions.ConnectionError)):
         if webhook['handle_attempts'] < webhook['attempts']:
             webhook['status'] = 0
         else:
             webhook['status'] = 2
         webhook['error_msg'] = str(sys.exc_info()[0].__name__)
         msg = "Unable to process webhook: {0}, reason: {1}"
         msg = msg.format(webhook['history_id'], helper.exc_info())
         LOG.warning(msg)
     elif isinstance(exc, (
             requests.exceptions.RequestException,
             requests.packages.urllib3.exceptions.HTTPError,
             requests.packages.urllib3.exceptions.HTTPWarning)):
         webhook['status'] = 2
         webhook['error_msg'] = str(sys.exc_info()[0].__name__)
         msg = "Unable to process webhook: {0}, reason: {1}"
         msg = msg.format(webhook['history_id'], helper.exc_info())
         LOG.warning(msg)
     else:
         webhook['status'] = 2
         webhook['error_msg'] = 'Internal error'
         msg = "Unable to process webhook: {0}, reason: {1}"
         msg = msg.format(webhook['history_id'], helper.exc_info())
         LOG.error(msg)
开发者ID:sacredwebsite,项目名称:scalr,代码行数:31,代码来源:dbqueue_event.py

示例4: _average

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def _average(self, results, ra=None, fa=None, rs=None, fs=None):
        ra = ra or dict()
        fa = fa or dict()
        rs = rs or dict()
        fs = fs or dict()
        for result in results:
            try:
                r_key, f_key = self._get_rf_keys(result)
                if 'snum' in self.config['metrics']:
                    rs.setdefault(r_key, {'snum': {'s_running': 0}})
                    fs.setdefault(f_key, {'snum': {'s_running': 0}})
                    rs[r_key]['snum']['s_running'] += 1
                    fs[f_key]['snum']['s_running'] += 1
                if not result['data']:
                    continue
                for metrics_group_name, metrics_data in result['data'].iteritems():
                    if not metrics_data or metrics_group_name == 'io':
                        continue
                    for metric_name, value in metrics_data.iteritems():
                        try:
                            ra.setdefault(r_key, {})
                            ra[r_key].setdefault(metrics_group_name, {})
                            ra[r_key][metrics_group_name].setdefault(metric_name, Average())

                            fa.setdefault(f_key, {})
                            fa[f_key].setdefault(metrics_group_name, {})
                            fa[f_key][metrics_group_name].setdefault(metric_name, Average())

                            ra[r_key][metrics_group_name][metric_name] += value
                            fa[f_key][metrics_group_name][metric_name] += value
                        except:
                            LOG.error(helper.exc_info())
            except:
                LOG.error(helper.exc_info())
        return ra, fa, rs, fs
开发者ID:afrank,项目名称:scalr,代码行数:37,代码来源:load_statistics.py

示例5: get_proxy_port

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
 def get_proxy_port(self):
     for szlr in self.szlrs:
         #if (szlr['uuid'] == uuid) and\
         #        (szlr['client_port'] == self.ctl_port):
         if szlr['client_port'] == str(self.ctl_port):
             return szlr['proxy_port']
     LOG.error("==================get_proxy_port failed! --Chen Leji==================")
     return None
开发者ID:chenleji,项目名称:scalr,代码行数:10,代码来源:floatingip_proxy.py

示例6: _set_usage_cost

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
 def _set_usage_cost(self, records):
     prices = self.analytics.get_prices(records)
     for record in records:
         cost = self.analytics.get_cost_from_prices(record, prices) or 0
         try:
             record['cost'] = float(cost) * int(record['num'])
         except:
             msg = 'Unable to update usage cost, reason: {error}'
             msg = msg.format(error=helper.exc_info())
             LOG.error(msg)
开发者ID:Zealsathish,项目名称:scalr,代码行数:12,代码来源:analytics_processing.py

示例7: process_credential

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
def process_credential(cred, envs_ids=None):
    if envs_ids is None:
        envs_ids = [cred.env_id]

    try:
        cloud_data = eval(cred.platform)(cred)
        if cloud_data:
            sorted_data = sort_nodes(cloud_data, cred, envs_ids)
            sorted_data_update(sorted_data)
            db_update(sorted_data, envs_ids, cred)
    except:
        msg = 'platform: {platform}, environments: {envs}, reason: {error}'
        msg = msg.format(platform=cred.platform, envs=envs_ids, error=helper.exc_info())
        LOG.error(msg)
开发者ID:Zealsathish,项目名称:scalr,代码行数:16,代码来源:analytics_poller.py

示例8: __call__

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def __call__(self):
        poller_ps, plotter_ps = None, None

        if self.args['--plotter']:
            plotter = Plotter(self.config)
            plotter_ps = plotter.run_in_process()
            time.sleep(5)
            if not plotter_ps.is_alive():
                LOG.critical('Failed to start CherryPy web server')
                sys.exit(1)

        self.change_permissions()

        if self.args['--poller']:

            poller = Poller(self.config, self.scalr_config)
            while True:
                start_time = time.time()
                try:
                    LOG.info('Start poller iteration')

                    rrdcached_sock_file = self.config['rrd']['rrdcached_sock_path']
                    if not os.path.exists(rrdcached_sock_file):
                        raise Exception('rrdcached process is not running')

                    poller_ps = poller.run_in_process()
                    poller_ps.join(self.config['interval'] * 2)
                    if poller_ps.is_alive():
                        LOG.error('Poller iteration timeout. Terminating')
                        try:
                            poller_ps.terminate()
                        except:
                            msg = 'Unable to terminate, reason: {error}'.format(
                                error=helper.exc_info())
                            raise Exception(msg)
                    LOG.info('Poller iteration time: %.2f' % (time.time() - start_time))
                except KeyboardInterrupt:
                    raise
                except:
                    msg = 'Poller iteration failed, reason: {error}'.format(
                        error=helper.exc_info())
                    LOG.error(msg)
                finally:
                    sleep_time = start_time + self.config['interval'] - time.time() - 0.1
                    if sleep_time > 0:
                        time.sleep(sleep_time)

        if plotter_ps:
            plotter_ps.join()
开发者ID:afrank,项目名称:scalr,代码行数:51,代码来源:load_statistics.py

示例9: do_iteration

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
 def do_iteration(self):
     servers = self.get_servers_for_update()
     for server in servers:
         try:
             self._pool.wait()
             self._pool.apply_async(self.update_server, (server,))
             gevent.sleep(0)  # force switch
         except:
             LOG.warning(helper.exc_info())
     self._pool.join()
     try:
         self.update_scalr_repo_data()
     except:
         msg = "Unable to update scalr.settings table, reason: {0}".format(helper.exc_info())
         LOG.error(msg)
开发者ID:complues,项目名称:scalr,代码行数:17,代码来源:szr_upd_service.py

示例10: _handle_exception

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
def _handle_exception(e, msg):
    if type(e) == boto.exception.EC2ResponseError and e.status in [401, 403]:
        LOG.warning(msg)
    elif type(e) in [
            libcloud.common.types.InvalidCredsError,
            libcloud.common.types.LibcloudError,
            libcloud.common.types.MalformedResponseError,
            gevent.timeout.Timeout,
            socket.timeout,
            socket.gaierror]:
        LOG.warning(msg)
    elif type(e) == socket.error and e.errno in [111, 113]:
        LOG.warning(msg)
    elif type(e) == googleapiclient.errors.HttpError and e.resp['status'] in ['403']:
        LOG.warning(msg)
    else:
        LOG.error(msg)
开发者ID:Zealsathish,项目名称:scalr,代码行数:19,代码来源:analytics_poller.py

示例11: load_statistics

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def load_statistics(self, **kwds):
        result = {'success': True}
        try:
            self._check_request(kwds)

            farm = self._get_farm(kwds['farmId'])
            if not farm or farm['status'] != 1:
                msg = 'Statistics are not available for terminated farms'
                raise Plotter.FarmTerminatedError(msg)
            if farm['hash'] != kwds['hash']:
                msg = 'Farm hash mismatch'
                raise Plotter.PlotterError(msg)

            tz = self._get_tz(kwds['farmId'])
            if tz:
                os.environ['TZ'] = tz

            metrics = kwds['metrics'].strip().split(',')
            for metric in metrics:
                try:
                    metric = metric.strip()
                    if metric not in ['cpu', 'la', 'mem', 'net', 'io', 'snum']:
                        msg = "Unsupported metric '%s'" % metric
                        raise Plotter.PlotterError(msg)
                    url = self._plot(kwds, tz, metric)
                    result.setdefault('metric', dict())
                    result['metric'][metric] = {'success': True, 'img': url}
                except Plotter.PlotterError as e:
                    result.setdefault('metric', dict())
                    result['metric'][metric] = {'success': False, 'msg': str(e)}
        except Plotter.PlotterError as e:
            result['success'] = False
            result['msg'] = str(e)
        except:
            result['success'] = False
            result['msg'] = 'Internal error. Unable to load statistics'
            LOG.error(helper.exc_info())
        cherrypy.response.headers['Access-Control-Allow-Origin'] = '*'
        cherrypy.response.headers['Access-Control-Max-Age'] = 300
        if 'Access-Control-Request-Headers' in cherrypy.request.headers:
            cherrypy.response.headers['Access-Control-Allow-Headers'] = \
                cherrypy.request.headers['Access-Control-Request-Headers']
        return result
开发者ID:afrank,项目名称:scalr,代码行数:45,代码来源:load_statistics.py

示例12: run

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
 def run(self):
     srv_pool = multiprocessing.pool.ThreadPool(self.config['pool_size'])
     rrd_pool = multiprocessing.pool.ThreadPool(10)
     try:
         rrd_sock = self.config['rrd']['rrdcached_sock_path']
         ra, fa, rs, fs = dict(), dict(), dict(), dict()
         for servers in self.get_servers():
             results = srv_pool.map(self._process_server, servers)
             for result in results:
                 if result['data']:
                     file_dir = os.path.join(
                         self.config['rrd']['dir'],
                         helper.x1x2(result['farm_id']),
                         '%s' % result['farm_id'],
                         'INSTANCE_%s_%s' % (result['farm_role_id'], result['index']))
                     rrd_pool.apply_async(
                         rrd.write,
                         args=(file_dir, result['data'],),
                         kwds={'sock_path': rrd_sock})
             ra, fa, rs, fs = self._average(results, ra=ra, fa=fa, rs=rs, fs=fs)
         for k, v in ra.iteritems():
             rrd_pool.apply_async(rrd.write, args=(k, v,), kwds={'sock_path': rrd_sock})
         for k, v in fa.iteritems():
             rrd_pool.apply_async(rrd.write, args=(k, v,), kwds={'sock_path': rrd_sock})
         if 'snum' in self.config['metrics']:
             for k, v in rs.iteritems():
                 rrd_pool.apply_async(rrd.write, args=(k, v,), kwds={'sock_path': rrd_sock})
             for k, v in fs.iteritems():
                 rrd_pool.apply_async(rrd.write, args=(k, v,), kwds={'sock_path': rrd_sock})
     except:
         LOG.error(helper.exc_info())
     finally:
         srv_pool.close()
         rrd_pool.close()
         srv_pool.join()
         rrd_pool.join()
开发者ID:afrank,项目名称:scalr,代码行数:38,代码来源:load_statistics.py

示例13: get_szr_ver_from_repo

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def get_szr_ver_from_repo(self, devel_branch=None, force=False):
        out = {}

        if devel_branch:
            if 'devel_repos' not in self.scalr_config['scalarizr_update']:
                return out
            if not force:
                try:
                    return self.get_szr_ver_from_repo.im_func.devel_cache[devel_branch]
                except AttributeError:
                    self.get_szr_ver_from_repo.im_func.devel_cache = {}
                except KeyError:
                    pass
            norm_branch = devel_branch.replace('/', '-').replace('_', '-')
            repos = self.scalr_config['scalarizr_update']['devel_repos']
        else:
            if not force:
                try:
                    return self.get_szr_ver_from_repo.im_func.cache
                except AttributeError:
                    pass
            repos = self.scalr_config['scalarizr_update']['repos']

        for repo_type, repo in repos.iteritems():
            try:
                # deb
                try:
                    deb_repo_url_template = repo['deb_repo_url']
                    if deb_repo_url_template:
                        deb_repo_url_template = deb_repo_url_template.strip()
                        if devel_branch:
                            deb_repo_url_template = deb_repo_url_template % norm_branch
                        try:
                            # try old style deb repo
                            deb_repo_url = '/'.join(deb_repo_url_template.split())
                            r = requests.get('%s/Packages' % deb_repo_url)
                            r.raise_for_status()
                        except requests.exceptions.HTTPError as e:
                            if e.response.status_code != 404:
                                raise
                            # try new style deb repo
                            deb_repo_url = '%s/dists/%s/%s/binary-amd64' % tuple(deb_repo_url_template.split())
                            r = requests.get('%s/Packages' % deb_repo_url)
                            r.raise_for_status()
                        out[deb_repo_url_template] = re.findall(
                                'Package: scalarizr\n.*?Version:([ A-Za-z0-9.]*)-?.*\n.*?\n',
                                r.text,
                                re.DOTALL)[0].strip()
                except:
                    msg = 'Deb repository {0} failed, reason: {1}'
                    msg = msg.format(repo_type, helper.exc_info())
                    LOG.error(msg)

                # rpm
                try:
                    rpm_repo_url_template = repo['rpm_repo_url']
                    if rpm_repo_url_template:
                        rpm_repo_url_template = rpm_repo_url_template.strip()
                        if devel_branch:
                            rpm_repo_url_template = rpm_repo_url_template % norm_branch
                        for release in ['5', '6']:
                            rpm_repo_url = rpm_repo_url_template.replace('$releasever', release)
                            rpm_repo_url = rpm_repo_url.replace('$basearch', 'x86_64')
                            r = requests.get('%s/repodata/primary.xml.gz' % rpm_repo_url)
                            r.raise_for_status()
                            s = StringIO.StringIO(r.content)
                            f = gzip.GzipFile(fileobj=s, mode='r')
                            f.seek(0)
                            xml = minidom.parse(f)
                            try:
                                out[rpm_repo_url_template] = re.findall(
                                        '<package type="rpm"><name>scalarizr-base</name>.*?ver="([ A-Za-z0-9.]*)-?.*".*?</package>\n',
                                        xml.toxml(),
                                        re.DOTALL)[0].strip()
                            except:
                                out[rpm_repo_url_template] = re.findall(
                                        '<package type="rpm"><name>scalarizr</name>.*?ver="([ A-Za-z0-9.]*)-?.*".*?</package>\n',
                                        xml.toxml(),
                                        re.DOTALL)[0].strip()
                except:
                    msg = 'RPM repository {0} failed, reason: {1}'
                    msg = msg.format(repo_type, helper.exc_info())
                    LOG.error(msg)

                # win
                try:
                    win_repo_url_template = repo['win_repo_url']
                    if win_repo_url_template:
                        win_repo_url_template = win_repo_url_template.strip()
                        if devel_branch:
                            win_repo_url = win_repo_url_template % norm_branch
                        win_repo_url = win_repo_url_template
                        r = requests.get('%s/x86_64/index' % win_repo_url)
                        r.raise_for_status()
                        out[win_repo_url_template] = re.findall(
                                'scalarizr *scalarizr_(.*).x86_64.exe*\n',
                                r.text,
                                re.DOTALL)[0].split('-')[0]
                except:
                    msg = 'Win repository {0} failed, reason: {1}'
#.........这里部分代码省略.........
开发者ID:Zealsathish,项目名称:scalr,代码行数:103,代码来源:szr_upd_service.py

示例14: download_billing_file

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def download_billing_file(self, env, date=None, force=False):
        date = date or datetime.datetime.utcnow().date()
        bucket_name = env['ec2.detailed_billing.bucket']
        if env.get('ec2.detailed_billing.payer_account'):
            envs = self.analytics.load_aws_accounts_ids_envs([env['ec2.detailed_billing.payer_account']])
            self.analytics.load_env_credentials(envs, platform='ec2')
            for e in envs:
                if e['client_id'] == env['client_id']:
                    credentials_env = e
                    break
            else:
                msg = 'Can not found AWS credentials for PayerAccount {}'
                msg = msg.format(env['ec2.detailed_billing.payer_account'])
                raise Exception(msg)
        else:
            credentials_env = env.copy()
        kwds = {
            'aws_access_key_id': cryptotool.decrypt_scalr(self.config['crypto_key'],
                                                          credentials_env['ec2.access_key']),
            'aws_secret_access_key': cryptotool.decrypt_scalr(self.config['crypto_key'],
                                                              credentials_env['ec2.secret_key']),
            'proxy': self.config['aws_proxy'].get('host'),
            'proxy_port': self.config['aws_proxy'].get('port'),
            'proxy_user': self.config['aws_proxy'].get('user'),
            'proxy_pass': self.config['aws_proxy'].get('pass'),
        }
        default_region_map = {
            'regular': 'us-east-1',
            'gov-cloud': 'us-gov-west-1',
            'cn-cloud': 'cn-north-1',
        }
        default_region = default_region_map[env.get('account_type', 'regular')]
        region = env.get('ec2.detailed_billing.region', default_region)
        conn = boto.s3.connect_to_region(region, **kwds)
        bucket = conn.get_bucket(bucket_name)
        default_file_name = get_default_aws_csv_file_name(credentials_env['ec2.account_id'], date)
        file_name_tmplate = get_aws_csv_file_name_tmplate(credentials_env['ec2.account_id'], date)
        files_in_bucket = [key.name for key in bucket.list()
                           if re.match(file_name_tmplate, key.name)]
        if not files_in_bucket:
            utcnow = datetime.datetime.utcnow()
            if date.month == utcnow.month and utcnow.day < 2:
                return None
            else:
                msg = "Not found any valid files({}, {}) in bucket '{}'"
                msg = msg.format(default_file_name, file_name_tmplate, bucket_name)
                raise exceptions.FileNotFoundError(msg)
        if default_file_name not in files_in_bucket:
            file_name = files_in_bucket[0]  # use first valid file
            msg = "Default AWS detailed billing statistics file '{}' not found in bucket '{}', available {}, use '{}'"
            msg = msg.format(default_file_name, bucket_name, files_in_bucket, file_name)
            LOG.warning(msg)
        else:
            file_name = default_file_name
        try:
            key = bucket.get_key(file_name)
            last_modified_dt = datetime.datetime.strptime(key.last_modified, self.last_modified_format)
            utcnow = datetime.datetime.utcnow()

            seconds_from_last_modified_dt = (utcnow - last_modified_dt).seconds
            if hasattr(self, 'task_info') and self.task_info.get('period') > 300:
                delta = datetime.timedelta(seconds=self.task_info['period'] - 90)
            else:
                delta = datetime.timedelta(seconds=210)
            condition1 = utcnow > last_modified_dt and utcnow < last_modified_dt + delta
            condition2 = seconds_from_last_modified_dt > 3600
            condition3 = (seconds_from_last_modified_dt / 3600) % 24 == 0

            if force or condition1 or (condition2 and condition3):
                with self._downloading_lock:
                    self.downloading_locks.setdefault(file_name, gevent.lock.RLock())
                with self.downloading_locks[file_name]:
                    csv_zip_file = os.path.join(self.cache_dir, file_name)
                    csv_file = csv_zip_file.rstrip('.zip')
                    if os.path.exists(csv_file):
                        msg = "'{}' already exists in cache directory, use it"
                        msg = msg.format(os.path.basename(csv_file))
                        LOG.debug(msg)
                        return csv_file
                    while key.size * 3 > helper.get_free_space(self.cache_dir):
                        LOG.error('Disk is full, waiting 60 sec')
                        gevent.sleep(60)
                    LOG.debug("Downloading '{}' for environment {}".format(file_name, env['id']))
                    attempts = 2
                    downloading_start_time = time.time()
                    while True:
                        try:
                            key.get_contents_to_filename(csv_zip_file)
                            assert os.path.isfile(csv_zip_file), os.listdir(self.cache_dir)
                            downloading_end_time = time.time()
                            break
                        except:
                            attempts -= 1
                            if not attempts:
                                raise
                    downloading_time = downloading_end_time - downloading_start_time
                    msg = "Downloading '{0}' done in {1:.1f} seconds".format(file_name, downloading_time)
                    LOG.info(msg)
                    LOG.debug('Unzipping to {}'.format(csv_file))
                    while os.path.getsize(csv_zip_file) * 1 > helper.get_free_space(self.cache_dir):
#.........这里部分代码省略.........
开发者ID:complues,项目名称:scalr,代码行数:103,代码来源:billing.py

示例15: do_iteration

# 需要导入模块: from scalrpy import LOG [as 别名]
# 或者: from scalrpy.LOG import error [as 别名]
    def do_iteration(self):
        try:
            dtime_from, dtime_to = self._get_processing_dtime()

            dtime_cur = dtime_from
            while dtime_cur <= dtime_to:
                date, hour = dtime_cur.date(), dtime_cur.hour
                try:
                    if self.config['recalculate']:
                        self.recalculate(date, hour)
                    else:
                        self.calculate(date, hour)
                except KeyboardInterrupt:
                    raise
                except:
                    LOG.error(helper.exc_info())
                dtime_cur += datetime.timedelta(seconds=3600)

            self._pool.join()

            if not self.config['recalculate']:
                return

            # recalculate daily tables
            dtime_cur = dtime_from
            while dtime_cur <= dtime_to:
                date = dtime_cur.date()
                msg = "Recalculate daily tables for date {0}".format(date)
                LOG.info(msg)
                try:
                    self.analytics.recalculate_usage_d(date, self.config['platform'])
                except:
                    msg = "Recalculate usage_d table for date {0} failed, reason: {1}"
                    msg = msg.format(date, helper.exc_info())
                    LOG.warning(msg)
                try:
                    self.analytics.recalculate_nm_usage_d(date, self.config['platform'])
                except:
                    msg = "Recalculate nm_usage_d table for date {0} failed, reason: {1}"
                    msg = msg.format(date, helper.exc_info())
                    LOG.warning(msg)
                dtime_cur += datetime.timedelta(days=1)

            # recalculate quarters tables
            quarters_calendar = self.analytics.get_quarters_calendar()
            start_year = quarters_calendar.year_for_date(dtime_from.date())
            start_quarter = quarters_calendar.quarter_for_date(dtime_from.date())
            end_year = quarters_calendar.year_for_date(dtime_to.date())
            end_quarter = quarters_calendar.quarter_for_date(dtime_to.date())

            tmp = []
            cur_year = start_year
            while cur_year < end_year:
                for quarter in range(start_quarter, 5):
                    tmp.append((cur_year, quarter))
                start_quarter = 1
                cur_year += 1

            for quarter in range(start_quarter, end_quarter + 1):
                tmp.append((end_year, quarter))

            for year, quarter in tmp:
                try:
                    msg = "Recalculate quarterly_budget table for year {0}, quarter {1}"
                    msg = msg.format(year, quarter)
                    LOG.debug(msg)
                    self.analytics.recalculate_quarterly_budget(year, quarter)
                except:
                    msg = "Recalculate quarterly_budget table for year {0}, quarter {1} failed, reason: {2}"
                    msg = msg.format(year, quarter, helper.exc_info())
                    LOG.warning(msg)
        except:
            if self.config['recalculate']:
                LOG.exception(helper.exc_info())
                sys.exit(1)
            else:
                raise

        # quit from iteration loop
        raise exceptions.QuitError()
开发者ID:Zealsathish,项目名称:scalr,代码行数:82,代码来源:analytics_processing.py


注:本文中的scalrpy.LOG.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。