def test_workflow_delay(self): """Test simple delayed workflow.""" from flask import current_app from invenio_workflows.models import BibWorkflowObject from invenio_workflows.api import start_delayed, continue_oid_delayed, start_by_wid_delayed from invenio_workflows.engine import WorkflowStatus current_app.config["WORKFLOWS_SNAPSHOTS_ENABLED"] = True test_objectb = BibWorkflowObject() test_objectb.set_data(20) test_objectb.save() from invenio_workflows.worker_result import uuid_to_workflow asyncr = start_delayed("demo_workflow", [test_objectb], module_name="unit_tests") engineb = asyncr.get(uuid_to_workflow) self.assertEqual(38, test_objectb.get_data()) asyncr = start_by_wid_delayed(engineb.uuid) asyncr.get(uuid_to_workflow) self.assertEqual(38, test_objectb.get_data()) test_objecte = BibWorkflowObject() test_objecte.set_data(2) test_objecte.save() asyncr = start_delayed("demo_workflow", [test_objecte], module_name="unit_tests") engineb = asyncr.get(uuid_to_workflow) asyncr = continue_oid_delayed(test_objecte.id) engineb = asyncr.get(uuid_to_workflow) self.assertEqual(WorkflowStatus.COMPLETED, engineb.status) self.assertEqual(20, test_objecte.get_data())
def test_workflow_delay(self): """Test simple delayed workflow.""" from invenio_workflows.models import BibWorkflowObject from invenio_workflows.api import (start_delayed, continue_oid_delayed, start_by_wid_delayed) from invenio_workflows.engine import WorkflowStatus test_objectb = BibWorkflowObject() test_objectb.set_data(20) test_objectb.save() from invenio_workflows.worker_result import uuid_to_workflow asyncr = start_delayed('demo_workflow', [test_objectb], module_name="unit_tests") engineb = asyncr.get(uuid_to_workflow) self.assertEqual(38, test_objectb.get_data()) asyncr = start_by_wid_delayed(engineb.uuid) asyncr.get(uuid_to_workflow) self.assertEqual(38, test_objectb.get_data()) test_objecte = BibWorkflowObject() test_objecte.set_data(2) test_objecte.save() asyncr = start_delayed('demo_workflow', [test_objecte], module_name="unit_tests") engineb = asyncr.get(uuid_to_workflow) asyncr = continue_oid_delayed(test_objecte.id) engineb = asyncr.get(uuid_to_workflow) self.assertEqual(WorkflowStatus.COMPLETED, engineb.status) self.assertEqual(20, test_objecte.get_data())
def report_exception(self, when, outrep_summary, location_tuple, formatted_exception=None, patches=None): error_data = {'rule_name': self.reporter.rule_name, 'when': when, 'outrep_summary': outrep_summary, 'location_tuple': location_tuple, 'formatted_exception': formatted_exception} start_delayed('simple_reporting_workflow', [error_data], module_name="checker")
def schedule_harvest(output, workflow, directory, name, records): """Select the output method, depending on the provided parameters. Default is stdout. :param output: The type of the output (stdout, workflow, dir/directory). :param workflow: The workflow that should process the output. :param directory: The directory that we want to send the harvesting results. :param name: The name of the OaiHARVEST object. :param records: A generator of harvested records. """ if output == "stdout": total = print_to_stdout(records) print_total_records(total) elif output == "dir" or output == "directory": files_created, total = write_to_dir(records, directory) print_files_created(files_created) print_total_records(total) elif output == "workflow": workflow_name = get_workflow_name(workflow, name) total = 0 # records is a generator object, hence special total counting for record in records: start_delayed(workflow_name, [record.raw]) total += 1 print_total_records(total) else: raise WrongOutputIdentifier("Output type not recognized.")
def report_exception(self, when, outrep_summary, location_tuple, formatted_exception=None, patches=None): error_data = { 'rule_name': self.reporter.rule_name, 'when': when, 'outrep_summary': outrep_summary, 'location_tuple': location_tuple, 'formatted_exception': formatted_exception } start_delayed('simple_reporting_workflow', [error_data], module_name="checker")
def test_workflows_tasks_chained(self): """Test delayed workflows in delayed workflow.""" from invenio_workflows.models import BibWorkflowObject from invenio_workflows.api import start_delayed from invenio_workflows.worker_result import uuid_to_workflow test_object = BibWorkflowObject() test_object.set_data(22) test_object.save() async = start_delayed("demo_workflow_workflows", [test_object], module_name="unit_tests") engine = async.get(uuid_to_workflow) from invenio_workflows.engine import WorkflowStatus self.assertEqual(21, engine.get_extra_data()["_nb_workflow_finish"]) self.assertEqual(0, engine.get_extra_data()["_nb_workflow_failed"]) self.assertEqual(WorkflowStatus.COMPLETED, engine.status)
def _finalize_and_post_process(obj, eng): from invenio_workflows.api import start_delayed from invenio_workflows.models import ObjectVersion obj.version = ObjectVersion.FINAL workflow_id = start_delayed(workflow_name, data=[obj], stop_on_error=True, **kwargs) obj.log.info("Started new workflow ({0})".format(workflow_id))