def run_workflow(records, name, **kwargs): """Run the uploader workflow itself. :param records: List of tuples `(blob, json_record)` from :func:`translate` :param name: Name of the workflow to be run. :parma kwargs: Additional arguments to be used by the tasks of the workflow :returns: Typically the list of record Ids that has been process, although this value could be modify by the `post_tasks`. """ def _run_pre_post_tasks(tasks): """Helper function to run list of functions.""" for task in tasks: task(records, **kwargs) #FIXME: don't know why this is needed but IT IS! records = records[0] if name in cfg['UPLOADER_WORKFLOWS']: workflow = workflows.get(name) else: raise UploaderException("Workflow {0} not in UPLOADER_WORKFLOWS".format(name)) _run_pre_post_tasks(workflow.pre_tasks) wfe = WorkflowEngine() wfe.setWorkflow(workflow.tasks) wfe.setVar('options', kwargs) wfe.process(records) _run_pre_post_tasks(workflow.post_tasks) signals.uploader_finished.send(uploader_workflow=name, result=records, **kwargs) return records
def run_workflow(records, name, **kwargs): """Run the uploader workflow itself. :param records: List of tuples `(blob, json_record)` from :func:`translate` :param name: Name of the workflow to be run. :parma kwargs: Additional arguments to be used by the tasks of the workflow :returns: Typically the list of record Ids that has been process, although this value could be modify by the `post_tasks`. """ def _run_pre_post_tasks(tasks): """Helper function to run list of functions.""" for task in tasks: task(records, **kwargs) #FIXME: don't know why this is needed but IT IS! records = records[0] if name in cfg['UPLOADER_WORKFLOWS']: workflow = workflows.get(name) else: raise UploaderException( "Workflow {0} not in UPLOADER_WORKFLOWS".format(name)) _run_pre_post_tasks(workflow.pre_tasks) wfe = WorkflowEngine() wfe.setWorkflow(workflow.tasks) wfe.setVar('options', kwargs) wfe.process(records) _run_pre_post_tasks(workflow.post_tasks) signals.uploader_finished.send(uploader_workflow=name, result=records, **kwargs) return records
def get_harvesting_workflows(): """Return the workflows enabled in the harvester module.""" enabled_workflows = [] for name in cfg.get("HARVESTER_WORKFLOWS", list()): if workflows.get(name): enabled_workflows.append(name) return enabled_workflows
def formatter(bwo): """Return description of object.""" from flask import render_template from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.registry import workflows identifiers = None extra_data = bwo.extra_data if 'options' in extra_data and 'identifiers' in extra_data["options"]: identifiers = extra_data["options"]["identifiers"] results = bwo.get_tasks_results() if 'review_workflow' in results: result_progress = results['review_workflow'][0]['result'] else: result_progress = {} current_task = extra_data['_last_task_name'] related_objects = [] for id_object in extra_data.get("objects_spawned", list()): spawned_object = BibWorkflowObject.query.get(id_object) if spawned_object: workflow = workflows.get(spawned_object.get_workflow_name()) related_objects.append( (spawned_object.id, workflow.get_title(spawned_object) or "No title") ) else: related_objects.append( (id_object, None) ) return render_template("workflows/styles/harvesting_description.html", identifiers=identifiers, result_progress=result_progress, current_task=current_task, related_objects=related_objects)
def formatter(bwo): """Return description of object.""" from flask import render_template from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.registry import workflows identifiers = None extra_data = bwo.get_extra_data() if 'options' in extra_data and 'identifiers' in extra_data["options"]: identifiers = extra_data["options"]["identifiers"] results = bwo.get_tasks_results() if 'review_workflow' in results: result_progress = results['review_workflow'][0]['result'] else: result_progress = {} current_task = extra_data['_last_task_name'] related_objects = [] for id_object in extra_data.get("objects_spawned", list()): spawned_object = BibWorkflowObject.query.get(id_object) if spawned_object: workflow = workflows.get(spawned_object.get_workflow_name()) related_objects.append( (spawned_object.id, workflow.get_title(spawned_object) or "No title")) else: related_objects.append((id_object, None)) return render_template("workflows/styles/harvesting_description.html", identifiers=identifiers, result_progress=result_progress, current_task=current_task, related_objects=related_objects)