def post(url, data={}, headers={}, cookies={}): """ Delegate a HTTP POST URL call via celery. Returns a <class 'celery.result.AsyncResult'> when running async, or a <class 'celery.result.EagerResult'> when running in sync mode. There is no callback, the assumption is that results are committed to the ZODB by the view called on `url`. DO NOT BYPASS CSRF FOR ACTUAL BUSINESS OBJECT WRITES like file previews. Instead, use the plone.protect support in ploneintranet.async.tasks. See https://pypi.python.org/pypi/plone.protect :param url: URL to be called by celery, resolvable behind the webserver (i.e. {portal_url}/path/to/object) :type url: str :param data: POST variables to pass through to the url :type data: dict :param headers: request headers. :type headers: dict :param cookies: request cookies. Normally contains __ac for Plone. :type cookies: dict """ # return value comes from celery @task not from here dispatch(url, data, headers, cookies)
def generate_and_add_preview(self, url, data={}, headers={}, cookies={}): """ Make an HTTP request to the DocConv Plone instance to generate a preview for the given object URL and add it to the object. See utils.dispatch() for interface contract. For info on acks_late and retries, see: - http://docs.celeryproject.org/en/latest/faq.html#faq-acks-late-vs-retry - http://docs.celeryproject.org/en/latest/userguide/tasks.html#retrying """ logger.info("START: generate_and_add_preview called.") conn = app.backend key = _key_for_task(url=url, task=self.name) counter = conn.client.get(key) if counter < 1: # behave conn.client[key] = 1 counter = conn.client.decr(key) logger.info("generate_and_add_preview: " + "I just decreased my key %s to %s " % (key, counter)) if counter > 0: logger.info("generate_and_add_preview: Counter > 0, aborting") return try: logger.info("generate_and_add_preview: Counter is 0, generating now") dispatch(url, data, headers, cookies) except DispatchError as exc: counter = conn.client.incr(key) raise self.retry(exc=exc)
def generate_and_add_preview(url, data={}, headers={}, cookies={}): """ Make an HTTP request to the DocConv Plone instance to generate a preview for the given object URL and add it to the object. See utils.dispatch() for interface contract. """ dispatch(url, data, headers, cookies)
def start_training(self): dispatch(self.id, train, algo_name=self.project.algorithm, params=json.loads(self.config), dataset_path=self.project.dataset.get_dataset_path(), experiment_name=self.log_name, logdir=get_config('LOG_DIR'))
def reindex_object(self, url, data={}, headers={}, cookies={}): """Reindex a content object. See utils.dispatch() for interface contract. For info on acks_late and retries, see: - http://docs.celeryproject.org/en/latest/faq.html#faq-acks-late-vs-retry - http://docs.celeryproject.org/en/latest/userguide/tasks.html#retrying """ try: dispatch(url, data, headers, cookies) except DispatchError as exc: raise self.retry(exc=exc)
def simulate_maxgain(network, shrinked_network, size=200, verbose=False, gauss=True): # Collect useful data from the original network contingent_pairs = network.contingentEdges.keys() contingents = {src: sink for (src, sink) in contingent_pairs} uncontrollables = set(contingents.values()) total_victories = 0 dc_network = STNtoDCSTN(shrinked_network) dc_network.addVertex(ZERO_ID) controllability = dc_network.is_DC() if verbose: print("Finished checking DC...") # Detect if the network has an inconsistency in a fixed edge verts = dc_network.verts.keys() for vert in verts: if (vert, vert) in dc_network.edges: if verbose: print("Checking", vert) edge = dc_network.edges[vert, vert][0] if edge.weight < 0: dc_network.edges[(vert, vert)].remove(edge) dc_network.verts[vert].outgoing_normal.remove(edge) dc_network.verts[vert].incoming_normal.remove(edge) del dc_network.normal_edges[(vert, vert)] # Run the simulation for j in range(size): realization = generate_realization(network, gauss) copy = dc_network.copy() result = dispatch(network, copy, realization, contingents, uncontrollables, verbose) if verbose: print("Completed a simulation.") if result: total_victories += 1 goodie = float(total_victories / size) if verbose: print(f"Worked {100*goodie}% of the time.") return goodie
def reindex_object(url, data={}, headers={}, cookies={}): """Reindex a content object. See utils.dispatch() for interface contract. """ dispatch(url, data, headers, cookies)
def mark_read(self, url, data={}, headers={}, cookies={}): try: dispatch(url, data, headers, cookies) except DispatchError as exc: raise self.retry(exc=exc)
def main(): fix_paths() args = parse_args() dispatch(args['command'], args)