Skip to content

Invoking workflows#

From the web application#

Since workflow require a User Interface, a web-app is required as front-end to interact with user providing at least: - Selection of Workflows to Start - Show outstanding Tasks - Show recent Tasks

the Buy Used Car example in the web application

From code, through the API#

To Invoke a process from your code:

API provides a security layer on top of the engine,See Security for more details. Every call names the user it runs for: a principal your application has authenticated.

import { BPMNServer, BPMNAPI, Logger, SecureUser, SystemUser } from 'bpmn-server';
import { configuration } from './configuration.js';

    const server = await BPMNServer.create(configuration, new Logger({ toConsole: false }), { cron: false });
    const api = new BPMNAPI(server);

    let response=await api.engine.start('Buy Used Car', {}, SystemUser);

    let instanceId=response.instance.id;

    console.log('Invoking Buy');

    response = await api.engine.invoke({instanceId , elementId: 'task_Buy' },
        { model: 'Thunderbird', needsRepairs: false, needsCleaning: false },SystemUser);
The above code uses SystemUser, to define another user:
    const user1 =new SecureUser({ userName: 'user1', userGroups: ['Owner', 'Others']});
In real applications, you get userName and userGroups from you application UserAccess.

Invoking remotely, over the API (example)#

NPM package 'bpmn-client' provide access to bpmn-server using remotely using webServices

import { BPMNClient } from 'bpmn-client';

const client = new BPMNClient(process.env.HOST, process.env.PORT, process.env.API_KEY);

let response = await client.engine.start('Buy Used Car');

Asynchronous execution#

The default behaviour is that engine.start and engine.invoke will execute the process in sequence specified in a synchronous fashion and returns control in one of these cases:

  1. Process has completed or Aborted; this happens when all active tokens come to completions
  2. All active tokens( threads) come to completion or wait state like in case of User Input, timers or Send Message

You can change this behaviour with the noWait option, so the call returns without waiting for the execution.

    const server = await BPMNServer.create(configuration, new Logger({ toConsole: false }), { cron: false });
    const api = new BPMNAPI(server);

    console.log('starting serviceTask');
    let response=await api.engine.start('serviceTask', { v1: 1, v2: 2 }, SystemUser, {noWait:true});

    let instanceId=response.instance.id;

    console.log('immediate response id',response.instance.id);
In the above example; engine.start return immediatly, but other nodes will continue to execute
starting serviceTask
immediate response id d7df99ab-f0b5-4fdf-8ac3-2701d0bf9b79
 add service start: { v1: 1, v2: 2 }
Add Service 5 3
Add Service 33 25
delaying ... 5000
delayed is done.
appDelegate service1 is now complete input: { repeat: '100', inputVar2: undefined } output: 1 item.data { v1: 1, v2: 2, result: 8, result2: 158 }
 service1 end: { v1: 1, v2: 2, result: 8, result2: 158 }

Comments