Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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)
Example #6
0
 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'))
Example #7
0
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)
Example #8
0
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
Example #9
0
def reindex_object(url, data={}, headers={}, cookies={}):
    """Reindex a content object.

    See utils.dispatch() for interface contract.
    """
    dispatch(url, data, headers, cookies)
Example #10
0
def mark_read(self, url, data={}, headers={}, cookies={}):
    try:
        dispatch(url, data, headers, cookies)
    except DispatchError as exc:
        raise self.retry(exc=exc)
Example #11
0
def main():
    fix_paths()
    args = parse_args()
    dispatch(args['command'], args)
Example #12
0
def reindex_object(url, data={}, headers={}, cookies={}):
    """Reindex a content object.

    See utils.dispatch() for interface contract.
    """
    dispatch(url, data, headers, cookies)