Exemplo n.º 1
0
 def start(self):
     super(RpcService, self).start()
     # TODO(hub-cap): Currently the context is none... do we _need_ it here?
     pulse = loopingcall.FixedIntervalLoopingCall(
         self.manager_impl.run_periodic_tasks, context=None)
     pulse.start(interval=self.report_interval,
                 initial_delay=self.report_interval)
     pulse.wait()
Exemplo n.º 2
0
 def add_timer(self,
               interval,
               callback,
               initial_delay=None,
               *args,
               **kwargs):
     pulse = loopingcall.FixedIntervalLoopingCall(callback, *args, **kwargs)
     pulse.start(interval=interval, initial_delay=initial_delay)
     self.timers.append(pulse)
Exemplo n.º 3
0
    def start(self):
        LOG.debug("Creating RPC server for service %s", self.topic)

        target = messaging.Target(topic=self.topic,
                                  server=self.host,
                                  version=self.rpc_api_version)

        if not hasattr(self.manager_impl, 'target'):
            self.manager_impl.target = target

        endpoints = [self.manager_impl]
        self.rpcserver = rpc.get_server(target, endpoints)
        self.rpcserver.start()

        # TODO(hub-cap): Currently the context is none... do we _need_ it here?
        if self.report_interval > 0:
            pulse = loopingcall.FixedIntervalLoopingCall(
                self.manager_impl.run_periodic_tasks, context=None)
            pulse.start(interval=self.report_interval,
                        initial_delay=self.report_interval)
            pulse.wait()
Exemplo n.º 4
0
def poll_until(retriever,
               condition=lambda value: value,
               sleep_time=1,
               time_out=None):
    """Retrieves object until it passes condition, then returns it.

    If time_out_limit is passed in, PollTimeOut will be raised once that
    amount of time is eclipsed.

    """
    start_time = time.time()

    def poll_and_check():
        obj = retriever()
        if condition(obj):
            raise loopingcall.LoopingCallDone(retvalue=obj)
        if time_out is not None and time.time() - start_time > time_out:
            raise exception.PollTimeOut

    lc = loopingcall.FixedIntervalLoopingCall(f=poll_and_check).start(
        sleep_time, True)

    return lc.wait()