multi_cell_monitor.py 文件源码

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

项目:treadmill 作者: Morgan-Stanley 项目源码 文件源码
def init():
    """Return top level command handler"""

    @click.command()
    @click.option('--cell', required=True,
                  envvar='TREADMILL_CELL',
                  callback=cli.handle_context_opt,
                  expose_value=False)
    @click.option('--monitor', nargs=2, type=click.Tuple([str, int]),
                  multiple=True, required=True)
    @click.option('--once', help='Run once.', is_flag=True, default=False)
    @click.option('--interval', help='Wait interval between checks.',
                  default=_DEFAULT_INTERVAL)
    @click.argument('name')
    def controller(monitor, once, interval, name):
        """Control app monitors across cells"""
        monitors = list(monitor)

        while True:

            intended_total = 0
            actual_total = 0
            intended = 0

            for cellname, count in monitors:
                if cellname == context.GLOBAL.cell:
                    intended = count
                else:
                    actual = _count(cellname, name)

                    _LOGGER.info('state for cell %s, actual: %s, intended: %s',
                                 cellname, actual, count)

                    intended_total += count
                    actual_total += actual

            missing = intended_total - actual_total

            # If there are missing instances, start them locally. If there are
            # extra instances (missing < 0) just keep the indended state for
            # the cell.
            my_count = intended + max(0, missing)
            _LOGGER.info('intended: %s, actual: %s, missing: %s, my count: %s',
                         intended_total, actual_total, missing, my_count)

            _configure_monitor(name, my_count)

            if once:
                break

            time.sleep(utils.to_seconds(interval))

    return controller
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号