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


Python timeutils.delta_seconds方法代码示例

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


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

示例1: log_enter_exit

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def log_enter_exit(func):
    if not CONF.debug:
        return func

    def inner(self, *args, **kwargs):
        LOG.debug("Entering %(cls)s.%(method)s.",
                  {'cls': self.__class__.__name__,
                   'method': func.__name__})
        start = timeutils.utcnow()
        ret = func(self, *args, **kwargs)
        end = timeutils.utcnow()
        LOG.debug("Exiting %(cls)s.%(method)s. "
                  "Spent %(duration)s sec. "
                  "Return %(return)s.",
                  {'cls': self.__class__.__name__,
                   'duration': timeutils.delta_seconds(start, end),
                   'method': func.__name__,
                   'return': ret})
        return ret

    return inner 
开发者ID:openstack,项目名称:manila,代码行数:23,代码来源:utils.py

示例2: get_service_status

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def get_service_status(self, context, service_id):
        service = objects.Service.get(context, service_id)
        last_heartbeat = (service.last_seen_up or service.updated_at or
                          service.created_at)
        if isinstance(last_heartbeat, str):
            # NOTE(russellb) If this service came in over rpc via
            # conductor, then the timestamp will be a string and needs to be
            # converted back to a datetime.
            last_heartbeat = timeutils.parse_strtime(last_heartbeat)
        else:
            # Objects have proper UTC timezones, but the timeutils comparison
            # below does not (and will fail)
            last_heartbeat = last_heartbeat.replace(tzinfo=None)
        elapsed = timeutils.delta_seconds(last_heartbeat, timeutils.utcnow())
        is_up = abs(elapsed) <= CONF.service_down_time
        if not is_up:
            LOG.warning('Seems service %(name)s on host %(host)s is down. '
                        'Last heartbeat was %(lhb)s. Elapsed time is %(el)s',
                        {'name': service.name,
                         'host': service.host,
                         'lhb': str(last_heartbeat), 'el': str(elapsed)})
            return objects.service.ServiceStatus.FAILED

        return objects.service.ServiceStatus.ACTIVE 
开发者ID:openstack,项目名称:watcher,代码行数:26,代码来源:scheduling.py

示例3: _set_status

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def _set_status(self, id):
        service = objects.Service.get(pecan.request.context, id)
        last_heartbeat = (service.last_seen_up or service.updated_at or
                          service.created_at)
        if isinstance(last_heartbeat, six.string_types):
            # NOTE(russellb) If this service came in over rpc via
            # conductor, then the timestamp will be a string and needs to be
            # converted back to a datetime.
            last_heartbeat = timeutils.parse_strtime(last_heartbeat)
        else:
            # Objects have proper UTC timezones, but the timeutils comparison
            # below does not (and will fail)
            last_heartbeat = last_heartbeat.replace(tzinfo=None)
        elapsed = timeutils.delta_seconds(last_heartbeat, timeutils.utcnow())
        is_up = abs(elapsed) <= CONF.service_down_time
        if not is_up:
            LOG.warning('Seems service %(name)s on host %(host)s is down. '
                        'Last heartbeat was %(lhb)s.'
                        'Elapsed time is %(el)s',
                        {'name': service.name,
                         'host': service.host,
                         'lhb': str(last_heartbeat), 'el': str(elapsed)})
            self._status = objects.service.ServiceStatus.FAILED
        else:
            self._status = objects.service.ServiceStatus.ACTIVE 
开发者ID:openstack,项目名称:watcher,代码行数:27,代码来源:service.py

示例4: service_is_up

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def service_is_up(self, member):
        if not isinstance(member, objects.ZunService):
            raise TypeError
        if member.forced_down:
            return False

        last_heartbeat = (member.last_seen_up or
                          member.updated_at or member.created_at)
        now = timeutils.utcnow()
        elapsed = timeutils.delta_seconds(last_heartbeat, now)
        is_up = abs(elapsed) <= self.service_down_time
        return is_up 
开发者ID:openstack,项目名称:zun,代码行数:14,代码来源:servicegroup.py

示例5: __call__

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def __call__(self):
        pstart, pend = self._my_range()
        LOG.info(
            "Refreshing zones for shards %(start)s to %(end)s",
            {
                "start": pstart,
                "end": pend
            })

        ctxt = context.DesignateContext.get_admin_context()
        ctxt.all_tenants = True

        # each zone can have a different refresh / expire etc interval defined
        # in the SOA at the source / master servers
        criterion = {
            "type": "SECONDARY"
        }
        for zone in self._iter_zones(ctxt, criterion):
            # NOTE: If the zone isn't transferred yet, ignore it.
            if zone.transferred_at is None:
                continue

            now = timeutils.utcnow(True)

            transferred = timeutils.parse_isotime(zone.transferred_at)
            seconds = timeutils.delta_seconds(transferred, now)
            if seconds > zone.refresh:
                msg = "Zone %(id)s has %(seconds)d seconds since last " \
                      "transfer, executing AXFR"
                LOG.debug(msg, {"id": zone.id, "seconds": seconds})
                self.central_api.xfr_zone(ctxt, zone.id) 
开发者ID:openstack,项目名称:designate,代码行数:33,代码来源:tasks.py

示例6: service_is_up

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def service_is_up(self, member):
        if not isinstance(member, magnum_service.MagnumService):
            raise TypeError
        if member.forced_down:
            return False

        last_heartbeat = (member.last_seen_up or
                          member.updated_at or member.created_at)
        now = timeutils.utcnow(True)
        elapsed = timeutils.delta_seconds(last_heartbeat, now)
        is_up = abs(elapsed) <= self.service_down_time
        return is_up 
开发者ID:openstack,项目名称:magnum,代码行数:14,代码来源:servicegroup.py

示例7: assert_timestamp_equal

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def assert_timestamp_equal(self, first, second, msg=None):
        """Checks that two timestamps are equals.

        This relies on assertAlmostEqual to avoid rounding problem, and only
        checks up the first microsecond values.

        """
        return self.assertAlmostEqual(timeutils.delta_seconds(first, second),
                                      0.0,
                                      places=5, msg=msg) 
开发者ID:openstack,项目名称:vitrage,代码行数:12,代码来源:base.py

示例8: chase_up

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def chase_up(start_time, interval, name='Poller'):
    """Utility function to check if there are missed intervals.

    :param start_time: A time object representing the starting time.
    :param interval: An integer specifying the time interval in seconds.
    :param name: Name of the caller for identification in logs.
    :returns: Number of seconds to sleep before next round.
    """
    end_time = timeutils.utcnow(True)
    elapsed = timeutils.delta_seconds(start_time, end_time)
    # check if we have missed any intervals?
    missed = int((elapsed - 0.0000001) / interval)
    if missed >= 1:
        LOG.warning("%s missed %s intervals for checking", name, missed)
    return (missed + 1) * interval - elapsed 
开发者ID:openstack,项目名称:senlin,代码行数:17,代码来源:health_manager.py

示例9: assertTimestampEqual

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def assertTimestampEqual(self, first, second, msg=None):
        """Checks that two timestamps are equals.

        This relies on assertAlmostEqual to avoid rounding problem, and only
        checks up the first microsecond values.

        """
        return self.assertAlmostEqual(
            timeutils.delta_seconds(first, second),
            0.0,
            places=5) 
开发者ID:openstack,项目名称:aodh,代码行数:13,代码来源:base.py

示例10: start

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def start(self, interval, initial_delay=None):
        self._running = True
        done = event.Event()

        def _inner():
            if initial_delay:
                greenthread.sleep(initial_delay)

            try:
                while self._running:
                    start = timeutils.utcnow()
                    self.f(*self.args, **self.kw)
                    end = timeutils.utcnow()
                    if not self._running:
                        break
                    delay = interval - timeutils.delta_seconds(start, end)
                    if delay <= 0:
                        LOG.warning('task run outlasted interval '
                                    'by %s sec',
                                    -delay)
                    greenthread.sleep(delay if delay > 0 else 0)
            except LoopingCallDone as e:
                self.stop()
                done.send(e.retvalue)
            except Exception:
                done.send_exception(*sys.exc_info())
                return
            else:
                done.send(True)

        self.done = done

        greenthread.spawn_n(_inner)
        return self.done


# TODO(mikal): this class name is deprecated in Havana and should be removed
# in the I release 
开发者ID:openstack,项目名称:oslo.vmware,代码行数:40,代码来源:loopingcall.py

示例11: resume_operation

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def resume_operation(self, operation_id, **kwargs):
        end_time = kwargs.get('end_time_for_run')
        now = datetime.utcnow()
        if not isinstance(end_time, datetime) or now > end_time:
            return

        window = int(timeutils.delta_seconds(now, end_time))
        param = {
            'operation_id': operation_id,
            'triggered_time': now,
            'expect_start_time': now,
            'window_time': window,
            'run_type': constants.OPERATION_RUN_TYPE_RESUME
        }
        self._execute_operation(operation_id, self._run_operation, param) 
开发者ID:openstack,项目名称:karbor,代码行数:17,代码来源:scheduled_operation_executor.py

示例12: resume_operation

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def resume_operation(self, operation_id, **kwargs):
        end_time = kwargs.get('end_time_for_run')
        now = datetime.utcnow()
        if not isinstance(end_time, datetime) or now > end_time:
            return

        window = int(timeutils.delta_seconds(now, end_time))
        param = {
            'operation_id': operation_id,
            'triggered_time': now,
            'expect_start_time': now,
            'window_time': window,
            'run_type': constants.OPERATION_RUN_TYPE_RESUME
        }
        self._create_thread(self._run_operation, operation_id, param) 
开发者ID:openstack,项目名称:karbor,代码行数:17,代码来源:green_thread_executor.py

示例13: get_min_interval

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def get_min_interval(self):
        try:
            t1 = self.compute_next_time(datetime.now())
            t2 = self.compute_next_time(t1)
            return timeutils.delta_seconds(t1, t2)
        except Exception:
            return None 
开发者ID:openstack,项目名称:karbor,代码行数:9,代码来源:crontab_time.py

示例14: get_min_interval

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def get_min_interval(self):
        """Get minimum interval of two adjacent time points

        :return: int(seconds) or None

        """
        try:
            t1 = self.compute_next_time(datetime.now())
            t2 = self.compute_next_time(t1)
            return timeutils.delta_seconds(t1, t2)
        except Exception:
            return None 
开发者ID:openstack,项目名称:karbor,代码行数:14,代码来源:calendar_time.py

示例15: _start

# 需要导入模块: from oslo_utils import timeutils [as 别名]
# 或者: from oslo_utils.timeutils import delta_seconds [as 别名]
def _start(self, first_run_time):
        self._running = True

        now = datetime.utcnow()
        initial_delay = 0 if first_run_time <= now else (
            int(timeutils.delta_seconds(now, first_run_time)))

        self._thread = eventlet.spawn_after(
            initial_delay, self._run, first_run_time)
        self._thread.link(self._on_done) 
开发者ID:openstack,项目名称:karbor,代码行数:12,代码来源:time_trigger.py


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