How to pick files in mutual exclusive way through automic?

48 Views Asked by At

We are receiving two different files in short interval of time from mainframes.we cannot predict the arrival sequence of files. These files should picked by two different workflow. But It should trigger in mutual exclusive way. In other word If one workflow is running then other workflow must be wait for previous workflow.

1

There are 1 best solutions below

0
On

This can be achieve to set some flag in common location. And every job should access that location and if that flag is set then wait for that flag to be unset.

Based of above statement I have create one file in unix server on particular location before executing any one workflow. Any workflow see that file on particular location if that file exist then it wait till that file remove by previous job which has started previously.

To create file and waiting for deletion of file below is the unix script. Which can be define in first job of the workflow in Pre-process tab.

#!/bin/bash
while true
do
        files=$(ls /u/users/lock 2> /dev/null | wc -l)
        if [ "$files" != "0" ]
        then
              echo "Other <workFlow name> is running wait for 10 second"
                sleep 10
        else
              echo "<workFlow name > is not running so <current workflow name> is starting"
              touch /u/users/lock
              exit 0
        fi
done

To delete the file at the end of workflow below is the unix script. This script must be define in last job in process tab.

#!/bin/bash
echo "<current workFlow name> is finshed so releasing the lock"
files=$(ls /u/users/lock 2> /dev/null | wc -l)
if [ "$files" != "0" ]
then
  rm /u/users/lock
fi