Basic introduction to CabloyJS built-in workflow engine
1. The origin of
As is known to all, NodeJS is a back-end development language and operating environment, which supports high concurrency and high development efficiency. However, NodeJS is mostly used in tool scenarios such as data CRUD management, mid-layer aggregation and mid-layer proxy, and rarely goes deep into the core of the business domain. This is one of the reasons there are so many minimum usable products (MVPS) developed with NodeJS that end up refactoring
As a business development platform, NodeJS still lacks many core basic components. NodeJS workflow engine is one of them. Since version 4.0, CabloyJS focuses on the development of NodeJS workflow engine. As the built-in basic core module (also open source and free), it further expands the application scenarios of NodeJS in the back end and provides the basic support for in-depth research and development of various commercial business logic
Characteristics of 2.
-
Easier configuration: Use JSON for process definition configuration, eliminating the complexity of XML configuration files
-
Clearer architecture: based on layered mechanism, multiple core modules are used to build the architecture of workflow engine, so that workflow is no longer mysterious, source code is no longer stacked
Concept and implementation of boundary events
1. Activiti boundary events
In the Activiti process engine, you can attach purpose-specific processing logic to process nodes through boundary events. For example, adding a timer boundary event to a process node automatically fires if the node does not finish executing within a specified time
2. CabloyJS node behavior
Because the nature of boundary events is to append specific behavior to process nodes. Therefore, CabloyJS uses a node behavior mechanism to implement functions similar to boundary events in Activiti
CabloyJS designs a unified development specification for node behavior, allowing third parties to develop custom node behavior types. The CabloyJS system itself will continue to add built-in node behavior types based on the actual needs and priorities of the business
3. The difference between boundary events and node behaviors
-
Simple configuration:
-
In Activiti, boundary events are configured by a single XML node and wired to the active node
-
In CabloyJS, the behavior configuration is added directly to the JSON configuration of the active node to make the process definition file more concise and compact
-
-
Easy to develop:
-
In Activiti, there are several built-in boundary events, and most scenarios are developed based on these, but few attempts have been made to develop custom boundary events
-
In CabloyJS, it provides a very clear programming interface, not only built-in common node behavior, but also allows the third party to develop very convenient custom node behavior types
-
demo
The following GIF demonstrates it:
-
Add a timeout behavior to the audit node, and the system automatically assigns a color to distinguish between different behaviors
-
Set the configuration of the behavior: duration
-
Pull a transfer line from the behavior to the drafting node
-
Effect: When the review is not completed after the specified time, it automatically moves to the drafting node
To further explore how to create a complete process definition, see:
-
Demo: CMS approval workflow
-
Demo: CMS Approval Workflow (Visual Editing)
JSON specification
In order to support node behavior, the active node JSON specification and the transfer line JSON specification are extended based on the original process definition. See:
-
The process defines the JSON specification
-
Active node JSON specification
-
JSON specification for transfer lines
1. Active node JSON specification
The Behaviors attribute is added to the regular active node JSON specification. Since multiple behaviors can be attached to a node, the behaviors are an array
{
id: 'activity_1'.name: 'Review'.type: 'activityUserTask'.options: {
assignees: {
vars: 'flowUser',}},behaviors: [{id: 'behavior_1'.name: 'Overtime'.type: 'overtime'.color: '#FF3B30'.options: {
cancelActivity: true.timeDuration: 3000,},},],},Copy the code
- behavior
The name of the | instructions |
---|---|
id | Behavior unique identification |
name | Name of behavior |
type | Types of behaviour |
color | Behavior color. Due to thebehavior Can also lead toThe transfer line , so it can be distinguished by different colors |
options | Behavior configuration, corresponding to different behavior types |
2. JSON specification of transfer line
The behavior attribute is added to the general JSON specification of the transfer line to identify the behavior Id corresponding to the transfer line
{
id: 'edge_3'.source: 'activity_1'.target: 'startEvent_1'.behavior: 'behavior_1',},Copy the code
The name of the | instructions |
---|---|
behavior | The correspondingBehavior Id , if not setnode Self elicitedThe transfer line |
A link to the
-
CabloyJS website: cabloy.com/
-
NodeJS workflow engine documentation: cabloy.com/zh-cn/artic…
-
GitHub source repository: github.com/zhennann/ca…