def run_workflow(ctx, fullname, payload):
    """Execute a workflow"""
    try:
        wf = cel_workflows.get_by_name(fullname)
        payload = json.loads(payload)

        if "schema" in wf:
            try:
                validate(payload, wf["schema"])
            except JsonValidationError as e:
                result = format_schema_errors(e)

                click.echo(f"Error: {result['error']}")
                for err in result["errors"]:
                    click.echo(f"- {err}")
                raise click.Abort()

    except WorkflowNotFound as e:
        click.echo(f"Error: {e}")
        raise click.Abort()
    except (JSONDecodeError) as e:
        click.echo(f"Error in the payload : {e}")
        raise click.Abort()

    # Create the workflow object
    project, name = fullname.split(".")
    obj = Workflow(project=project, name=name, payload=payload)
    obj.save()

    # Build the canvas and execute it
    _workflow = WorkflowBuilder(obj.id)
    _workflow.run()
Example #2
0
def execute(workflow, payload):
    project, name = workflow.split(".")
    c_obj = Workflow(project=project,
                     name=name,
                     payload=payload,
                     periodic=True)
    c_obj.save()

    # Build the workflow and execute it
    workflow = WorkflowBuilder(c_obj.id)
    workflow.run()

    return c_obj.to_dict()
def execute(workflow, payload):
    project, name = workflow.split(".")
    c_obj = Workflow(project=project, name=name, payload=payload, periodic=True)
    c_obj.save()

    # Build the workflow and execute it
    workflow = WorkflowBuilder(c_obj.id)
    workflow.run()

    c_obj_dict = c_obj.to_dict()

    # Force commit before ending the function to ensure the ongoing transaction
    # does not end up in a "idle in transaction" state on PostgreSQL
    c_obj.commit()

    return c_obj_dict
Example #4
0
def run_workflow(ctx, fullname, payload):
    """Execute a workflow"""
    try:
        cel_workflows.get_by_name(fullname)
        payload = json.loads(payload)
    except WorkflowNotFound as e:
        click.echo(f"Error: {e}")
        raise click.Abort()
    except JSONDecodeError as e:
        click.echo(f"Error parsing the JSON payload : {e}")
        raise click.Abort()

    # Create the workflow object
    project, name = fullname.split(".")
    obj = Workflow(project=project, name=name, payload=payload)
    obj.save()

    # Build the canvas and execute it
    _workflow = WorkflowBuilder(obj.id)
    _workflow.run()
Example #5
0
def _execute_workflow(project, name, payload={}):
    fullname = f"{project}.{name}"

    # Check if the workflow exists
    try:
        cel_workflows.get_by_name(fullname)
    except WorkflowNotFound:
        abort(404, f"Workflow {fullname} not found")

    # Create the workflow in DB
    obj = Workflow(project=project, name=name, payload=payload)
    obj.save()

    # Build the workflow and execute it
    data = obj.to_dict()
    workflow = WorkflowBuilder(obj.id)
    workflow.run()

    app.logger.info(f"Workflow sent : {workflow.canvas}")
    return obj.to_dict(), workflow
Example #6
0
def create_workflow():
    data = request.get_json()
    project = data["project"]
    name = data["name"]
    fullname = f"{project}.{name}"

    # Check if the workflow exists
    try:
        cel_workflows.get_by_name(fullname)
    except WorkflowNotFound:
        return jsonify({"error": f"Workflow {fullname} not found"}), 404

    # Create the workflow in DB
    obj = Workflow(project=project, name=name, payload=data["payload"])
    obj.save()

    # Build the workflow and execute it
    data = obj.to_dict()
    workflow = WorkflowBuilder(obj.id)
    workflow.run()

    app.logger.info(f"Workflow ready : {workflow.canvas}")
    return jsonify(data), 201