host.py 文件源码

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

项目:discovery 作者: lyft 项目源码 文件源码
def _is_expired(self, host):
        """Check if the given host is considered to be expired.

        Expiration is based on the value of HOST_TTL.

        :param host: the host dictionary with check in info

        :type: list(dict)

        :returns: True if host entry expired, False otherwise
        :rtype: bool
        """

        last_check_in = host['last_check_in']
        now = pytz.utc.localize(datetime.datetime.utcnow())

        if not last_check_in.tzinfo:
            last_check_in = pytz.utc.localize(last_check_in)
        # datetime.now(tz.tzutc()) and datetime.utcnow() do not return a tz-aware datetime
        # as a result, we use pytz to localize the timestamp to the UTC timezone
        time_elapsed = (now - last_check_in).total_seconds()
        if time_elapsed > settings.value.HOST_TTL:
            logging.info(
                "Expiring host %s for service %s because %d seconds have elapsed since last_checkin"
                % (host['tags']['instance_id'], host['service'], time_elapsed)
                )
            return True
        else:
            return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号