def register_server(self): environment = dict_get(get_server_meta(), ["environment"]) service = dict_get(get_server_meta(), ["name"]) endpoint_parts = { 'port': get_server_port(), 'path': "api/%s" % self.name, } self.service_dir_client.set_endpoint(environment=environment, service=service, endpoint_parts=endpoint_parts)
def register_server(self): environment = dict_get(get_server_meta(), ["environment"]) service = dict_get(get_server_meta(), ["name"]) endpoint_parts = { 'port': get_server_port(), 'path': "api/%s" % self.name, } self.service_dir_client.set_endpoint( environment=environment, service=service, endpoint_parts=endpoint_parts)
def poll_endpoints(server_meta): # set server meta for this thread set_server_meta(server_meta) while True: self.service_endpoints = self.get_all_endpoints( environment=dict_get( get_server_meta(), ["environment"], DEFAULT_ENVIRONMENT)) sleep(SERVICE_UPDATE_INTERVAL)
def get_all_endpoints(self, environment=None): if environment is None: return self.service_endpoints return dict_get(self.service_endpoints, [environment], {})
def get_endpoint(self, environment=DEFAULT_ENVIRONMENT, service=None): return dict_get(self.service_endpoints, [environment, service], None)
def get_services(self, environment=DEFAULT_ENVIRONMENT): return dict_get(self.service_endpoints, ['environment'], {}).keys()
def get_request_id(): return dict_get(get_threadlocal(), ["request_meta", "request_id"], None)
def get_server_name(self): return dict_get(get_server_meta(), ["name"])
def get_server_meta(): server_meta = dict_get(get_threadlocal(), ["server_meta"], {}) set_server_meta(server_meta) return server_meta
def get_request_meta(): request_meta = dict_get(get_threadlocal(), ["request_meta"], {}) # write back dictionary in case it was newly created set_request_meta(request_meta) return request_meta