Synchronize Business Processes
While designing a solution using WorkFusion Business Process Management (BPM), it is helpful to use a synchronization design pattern.
Assume you have two Business Processes. If Business Process 1 (BP 1) is in run, you cannot run Business Process 2 (BP 2) in parallel. Both BPs can run on schedule. BP 2 should automatically detect if BP 1 is running; if it is, the BP 2 flow goes to its end.
BP 1

Set sync flag
<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<var-def name="sync_datastore">sync_bp</var-def>
<var-def name="sync_variable">sync_bp_flag</var-def>
<var-def name="sync_variable_set_value">BUSY</var-def>
<datastore name="${sync_datastore}" max="1">
<template>
update @this set ${sync_variable}='${sync_variable_set_value}'
</template>
</datastore>
<export include-original-data="true"></export>
</config>
Long-lasting task
<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<script></script>
<export include-original-data="true">
</export>
</config>
Drop sync flag
<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<var-def name="sync_datastore">sync_bp</var-def>
<var-def name="sync_variable">sync_bp_flag</var-def>
<var-def name="sync_variable_set_value">AVAILABLE</var-def>
<datastore name="${sync_datastore}" max="1">
<template>
update @this set ${sync_variable}='${sync_variable_set_value}'
</template>
</datastore>
<export include-original-data="true"></export>
</config>
BP 2

Read sync flag
<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<var-def name="sync_datastore">sync_bp</var-def>
<var-def name="sync_variable">sync_bp_flag</var-def>
<var-def name="syncRecord">
<datastore name="${sync_datastore}" max="1">
<template>
select * from @this
</template>
</datastore>
</var-def>
<export include-original-data="true">
<var-def name="value">
<xpath expression='/row/${sync_variable}/text()'>
<var name="syncRecord"/>
</xpath>
</var-def>
<single-column name="${sync_variable}" value="${value}"/>
</export>
</config>
Concurrent long-lasting task
<?xml version="1.0" encoding="UTF-8"?>
<config charset="UTF-8">
<script></script>
<export include-original-data="true">
</export>
</config>
Simple synchronization Data Store

Test execution
If you put both BPs into the WF instance and create this simple Data Store, you can test the synchronization as follows:
- Execute BP 1. It sets a flag and sleeps for one minute on the second Bot Task.
- Execute BP 2. The flow is transitioned into the end without executing the concurrent long-lasting task.
- Execute BP 2 again. This time, it goes to the concurrent long-lasting task.