Exemplo n.º 1
0
def robotupload_callback():
    """Handle callback from robotupload.

    If robotupload was successful caches the workflow
    object id that corresponds to the uploaded record,
    so the workflow can be resumed when webcoll finish
    processing that record.
    If robotupload encountered an error sends an email
    to site administrator informing him about the error."""
    request_data = request.get_json()
    id_object = request_data.get("nonce", "")
    results = request_data.get("results", [])
    status = False
    for result in results:
        status = result.get('success', False)
        if status:
            recid = result.get('recid')
            pending_records = cache.get("pending_records") or dict()
            pending_records[str(recid)] = str(id_object)
            cache.set("pending_records", pending_records,
                      timeout=current_app.config["PENDING_RECORDS_CACHE_TIMEOUT"])
        else:
            from invenio_mail.tasks import send_email

            body = ("There was an error when uploading the "
                    "submission with id: %s.\n" % id_object)
            body += "Error message:\n"
            body += result.get('error_message', '')
            send_email.delay(dict(
                sender=current_app.config["CFG_SITE_SUPPORT_EMAIL"],
                receipient=current_app.config["CFG_SITE_ADMIN_EMAIL"],
                subject='BATCHUPLOAD ERROR',
                body=body
            ))
    return jsonify({"result": status})
Exemplo n.º 2
0
def webcoll_callback():
    """Handle a callback from webcoll with the record ids processed.

    Expects the request data to contain a list of record ids in the
    recids field.
    """
    recids = dict(request.form).get('recids', [])
    pending_records = cache.get("pending_records") or dict()
    for rid in recids:
        if rid in pending_records:
            objectid = pending_records[rid]
            workflow_object = workflow_object_class.get(objectid)
            base_url = _get_base_url()
            workflow_object.extra_data['url'] = join(
                base_url, 'record', str(rid)
            )
            workflow_object.extra_data['recid'] = rid
            workflow_object.save()
            db.session.commit()
            workflow_object.continue_workflow(delayed=True)
            del pending_records[rid]
            cache.set("pending_records", pending_records,
                      timeout=current_app.config["PENDING_RECORDS_CACHE_TIMEOUT"])
    return jsonify({"result": "success"})