I recently worked on large scale data integration project with a requirement to notify the calling web-based application of a successful GL data load and, in the event of failure, send a point of failure message. There were 160 locations.
The solution involved executing a stored procedure that updated a table in the web applications schema — simple enough.
There could have been potentially 18 FDMEE Event Scripts where a Location could fail during the Workflow, so it was important to minimize the number of lines of code as much as possible so it would be easier to debug and maintain. A Python Module was clearly the way to go. A module is simply a script in which functions, classes or variables are defined and helps organize your code.
These were the steps:
First, I created the Module with a function to execute the Stored Procedure.
Two things I’d like to point out about this code:
- I imported the JAVA Package “java.sql”. I could have used the zxJDBC Jython package which provides a wrapper around JDBC to execute the store procedure. I didn’t because I used similar Java code many times in Java programs I worked on over the years, and I love the fact you can use Java classes in your Jython code.
- I imported the “fdmApi” into the Module so I could update the Process ID log file for the Location in the case where it may have failed executing the store procedure.
With the Jython Module in place, the sequence is the same when calling the Function from any of the Event Scripts with the following steps:1. Make sure to tell the Event Script the location of the Module by adding it to the sys path
custModPath=sScriptsDir + '/event'
sys.path.append(custModPath)2. Determine the Event Status to decide what status info to pass
iStatus = fdmAPI.getProcessStates(sProcessID)3. Import the Module into the Event Script
import updateFDMEESTATUS as custLib4. Set variable based on results, execute the Module Function
custLib.updateFDMEESTATUS(sAppName, sLocation, fdmAPI, sStatus, sMessage)
Step 4 is the key. This one line in each Event Script reduces the code from 20 lines to 1, making it easier to maintain. In addition, if any change is required to the stored procedure code you would only need to make changes in one place.
Taking advantage of Modules in Jython is one way to make your code easier to maintain, modify and organize, which is critical when working on large scale implementations.