def start(self): verstr = '0.0.2' LOG.info(_LI('Starting %(topic)s node (version %(version)s'), {'topic': self.topic, 'version': verstr}) ctxt = context.get_admin_context() # self.manager.pre_start_hook() LOG.debug("Creating RPC server for service %s", self.topic) target = messaging.Target(topic=self.topic, server=self.host) endpoints = [ self.manager ] self.rpcserver = rpc.get_rpc_server(target, endpoints) self.rpcserver.start() # self.manager.post_start_hook() # periodic_enable set false for the moment. # I just focus on rpc process. if self.periodic_enable: if self.periodic_fuzzy_delay: initial_delay = random.randint(0, self.periodic_fuzzy_delay) else: initial_delay = None self.tg.add_dynamic_timer(self.periodic_tasks, initial_delay=initial_delay, periodic_interval_max= self.periodic_interval_max)
def index(self, req): ctxt = context.get_admin_context() result = rpcapi.EngineAPI().index(ctxt) response = Response( request=req, status=httplib.MULTIPLE_CHOICES, content_type='application/json') response.body = json.dumps(dict(result=result)) # response.body = json.dumps(dict(author=self.author)) return response
def periodic_tasks(self, raise_on_error=False): """Tasks to be run at a periodic interval.""" ctxt = context.get_admin_context() return self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)