def _backoff_request(self, url, method, payload=None, num_attempts=1, initial_wait=0, need_result=True, callback=None): initial_wait = 5 for _ in range(0, num_attempts): if self.stop_event.is_set(): break try: try: if method == "POST": if need_result or num_attempts > 1: content = post_string(url, payload) else: if callback is None: callback = self.master_post_result_callback post_string_noreturn(url, payload, result_callback=callback) return elif method == "GET": content = get_string(url) else: raise Exception("Invalid method %s" % method) return 200, content except Exception as e: ciel.log("Backoff-request failed with exception %s; re-raising MasterNotResponding" % e, "MASTER_PROXY", logging.ERROR) raise MasterNotRespondingException() except: ciel.log.error("Error contacting master", "MSTRPRXY", logging.WARN, True) self.stop_event.wait(initial_wait) initial_wait += initial_wait * random.uniform(0.5, 1.5) ciel.log.error("Given up trying to contact master", "MSTRPRXY", logging.ERROR, True) if self.stop_event.is_set(): raise WorkerShutdownException() else: raise MasterNotRespondingException()
def backoff_request(self, url, method, payload=None, need_result=True, callback=None): if self.stop_event.is_set(): return try: if method == "POST": if need_result: content = post_string(url, payload) else: if callback is None: callback = self.master_post_result_callback post_string_noreturn(url, payload, result_callback=callback) return elif method == "GET": content = get_string(url) else: raise Exception("Invalid method %s" % method) return 200, content except: ciel.log("Error attempting to contact master, aborting", "MSTRPRXY", logging.WARNING, True) raise
def create_job_for_process(self, record): ref = self.get_reference_for_process(record) root_task_descriptor = {'handler' : 'proc', 'dependencies' : [ref], 'task_private' : ref} master_task_submit_uri = urlparse.urljoin(self.worker.master_url, "control/job/") try: message = simplejson.dumps(root_task_descriptor, cls=SWReferenceJSONEncoder) content = post_string(master_task_submit_uri, message) except Exception, e: ciel.log('Network error submitting process job to master', 'PROCESSPOOL', logging.WARN) raise e
def _backoff_request(self, url, method, payload=None, num_attempts=1, initial_wait=0, need_result=True, callback=None): initial_wait = 5 for _ in range(0, num_attempts): if self.stop_event.is_set(): break try: try: if method == "POST": if need_result or num_attempts > 1: content = post_string(url, payload) else: if callback is None: callback = self.master_post_result_callback post_string_noreturn(url, payload, result_callback=callback) return elif method == "GET": content = get_string(url) else: raise Exception("Invalid method %s" % method) return 200, content except Exception as e: ciel.log( "Backoff-request failed with exception %s; re-raising MasterNotResponding" % e, "MASTER_PROXY", logging.ERROR) raise MasterNotRespondingException() except: ciel.log.error("Error contacting master", "MSTRPRXY", logging.WARN, True) self.stop_event.wait(initial_wait) initial_wait += initial_wait * random.uniform(0.5, 1.5) ciel.log.error("Given up trying to contact master", "MSTRPRXY", logging.ERROR, True) if self.stop_event.is_set(): raise WorkerShutdownException() else: raise MasterNotRespondingException()
def create_job_for_process(self, record): ref = self.get_reference_for_process(record) root_task_descriptor = { 'handler': 'proc', 'dependencies': [ref], 'task_private': ref } master_task_submit_uri = urlparse.urljoin(self.worker.master_url, "control/job/") try: message = simplejson.dumps(root_task_descriptor, cls=SWReferenceJSONEncoder) content = post_string(master_task_submit_uri, message) except Exception, e: ciel.log('Network error submitting process job to master', 'PROCESSPOOL', logging.WARN) raise e