Improved Batch Options for Summaries & Reports Job Streams
Often times, you may have the desire to run Summary applications or Reports outside of normal business hours or periodically throughout the day. That is, you may wish to automate Summaries to run to populate data-marts throughout the day. Likewise, you might want to have a Report run in the middle of the night to automatically e-mail you the results. All of this can be done with our Job-Stream functionality.
Note: This feature requires JDK 1.6. Please click here to learn about installing JDK 1.6 on the AS400/Linux or on a Windows server.
On your server, you will find the following files:
Non-Windows Users
/m-power/mrc_execute_jobs_400.sh (no configuration needed)
/m-power/mrc_schedule_jobs_400.sh (no configuration needed)
/m-power/mrcjava/job_streams/example_execute_jobs.bat
/m-power/mrcjava/job_streams/example_schedule_jobs.bat
/m-power/mrcjava/job_streams/example_schedule_jobs_400.js
/m-power/mrcjava/job_streams/example_execute_jobs_400.js
/m-power/mrcjava/WEB-INF/classes/mrc_email.properties-dist
Windows Users
\m-power\mrc_schedule_jobs.bat (no configuration needed)
\m-power\mrc_execute_jobs.bat (no configuration needed)
\m-power\mrcjava\job_streams\example_execute_jobs.bat <– Calls the execute.js file to run
\m-power\mrcjava\job_streams\example_schedule_jobs.bat <– Calls the schedule.js file to run
\m-power\mrcjava\job_streams\example_execute_jobs.js <– Provides the logic for executing applications
\m-power\mrcjava\job_streams\ example_schedule_jobs.js <– Provides the logic for scheduling applications
\m-power\mrcjava\WEB-INF\classes\mrc_email.properties-dist <– Serves as a global file for e-mail logic (such as default from, to & server information)
Because most clients decide to run a production environment from a Windows server, due to speed and stability, these instructions will focus on the Windows configuration.
The batch process allows you two options:
- Execute your Job (and schedule it through your OS)
- Schedule your Job through mrc's Scheduler (a great option if you are unfamiliar with scheduling via your OS).
In our first scenario, let's look at executing a job & scheduling it through your OS.
Executing a Job
The Example_execute_jobs.js provides many great examples. Let's copy it so we can make a few modifications. Let's call this file "test_execute.js".
In the first section, you have the option of creating any parameter necessary for your prompt. This is quite useful if you want to send parameters to your applications that might change (i.e. the date). In our example, we are using Javascript to determine a date range. Feel free to utilize this script, create a new one, or simply ignore this section if you wish to have no dynamic record selection.
Syntax for Calling a Summary
Next, if you wish to call a summary use this syntax:
MRCWORKLIB_S01021s.runCmd([]);
<– Passes no parameters
MRCWORKLIB_S01021s.runCmd([20, 30]);
<– Passes two parameters — R001 = 20, R002= 30
MRCWORKLIB_S01021s.runCmd(["20 30"]);
<– Passes one "Is in the Range" parameter — R001 = 20, S001 = 30
Note: The "_" separates the data dictionary and the summary name.
While a summary automatically writes to the database, a report, by default, only prints to the screen. The batch job allows you save the report to the server's hard disk. Once there, you have the opportunity to e-mail it. This tool uses the standard output formats for reports (0 — HTML, 1 — Print-Optimized HTML , 10 — Excel, 11 — PDF) to let you select the output saved.
Syntax for Calling a Report
MRCWORKLIB_R00060s.runCmd(["c:/temp/R60.html","0", 995]);
<–Outputs the report to c:\temp\R60.html in html format, passes R001 as 995.
MRCWORKLIB_R00060s.runCmd(["c:/temp/R60o.html","1"]);
<– Outputs the report to c:\temp\R60.html in print-optimized html format (no record selection).
MRCWORKLIB_R00060s.runCmd(["c:/temp/R60.xls","10"]);
<– Outputs the report to c:\temp\R60.html in Excel format (no record selection).
MRCWORKLIB_R00060s.runCmd(["c:/temp/R60.pdf","11"]);
<– Outputs the report to c:\temp\R60.html in PDF format (no record selection).
Note: The location (in this case, C:\temp) must exist prior to the Batch command being run. If the directory does not exist, no output will be saved.
Syntax for Calling a Cross Tab Report
MRCWORKLIB_R00060s.runCmd(["c:/temp/R60.html","0"], "CLASS" );
<– Outputs the Cross Tab report to c:\temp\R60.html in HTML format with the "CLASS" field selected as the variable column dimension.
Note: The "CLASS" variable is needed for the Cross Tab report in order to specify which field to use for the column dimension.
E-mailing a Report
Lastly, we have the option to e-mail a report's output. The email option sends any report once it has been generated to the hard disk. First, rename mrc_email.properties-dist to mrc_email.properties in c:\m-power\mrcjava\WEB-INF\classes as this will "load" the ability for your batch jobs to be able to e-mail.
Note: You must list a valid email_host in the mrc_email.properties file located in \m-power\mrcjava\WEB-INF\classes\.
You must also list the "from address", "to address", File name (outfilename), File location (outfile), the format (outfmt), a subject and any body text.
The email.send option takes all of the parameters listed and sends the email to the appropriate addresses.
Note: You have the option of listing the from, and to addresses within the mrc_email.properties by commenting out (adding // to the beginning of the line) the first email.send.
Note: You can only send one file per email. If you wish to send multiple reports, you must duplicate the email.send line, being sure to modify all appropriate parameters.
One the test_execute.js file has been saved, we will need to copy the example_execute_jobs.bat file. Let's call it "test_execute.bat".
Edit the file in notepad. Modify this line:
mrc_schedule_jobs c:/m-power/mrcjava/job_streams/example_schedule_jobs.js
so it looks like this:
mrc_schedule_jobs c:/m-power/mrcjava/job_streams/test_execute.js
Note: If m-Power is installed within C:\Program Files, please adjust the above syntax accordingly.
Save the file. We have just told the batch file to point to our new logic.
To verify that we have successfully created our logic, double click the test_execute.bat file. Your summary or report (depending on what you defined in tet_execute.js) should have run successfully. If it has, congratulations! If not, please see the Common Questions listed below for troubleshooting. The final step will be scheduling this job so it happens regularly. This can be done with the OS400's Job Scheduler (WRKJOBSCDE) if you are utilizing the AS400. If you are utilizing a Windows operating system, you could use Windows' Scheduled Tasks.
Scheduling a Job
While mrc recommends scheduling jobs via your OS (using the execute option described above), we have also shipped the option to schedule jobs for users not familiar with scheduling via their OS. To schedule a job, utilize the example_schedule_jobs.js file. It is identical to the example_execute_jobs.js file except for the following text which tells the job when to run:
var schedule_expr = "6 45 18 ? * MON-FRI";
<– Runs at 6:45 PM every night, Monday through Friday.
The syntax of this scheduling can be found at the end of the example_execute_jobs.js file.
Note: For mrc's shipped version of Scheduling to run, the command window must remain open. If the DOS window is closed, the job will no longer run for it's scheduled time until the window has been reopened.
Some Common Questions:
I think I've done everything right, but my report doesn't show up/no data is written to my summary. When I double click my .bat file, the window opens and closes too fast to read it. What can I do?
Click Start –> Run. Type CMD
. From here navigate to c:\m-power\mrcjava\job_streams. Type the name of your .bat file here. Any text will remain on the screen. This will be useful to send to mrc support, if necessary.
I have done what you suggest above, now I get this error:
This error message states that you do not have the correct JDK level installed. Please install JDK 1.6 and configure your m-Power instance to utilize JDK 1.6.
I get this error message sometimes. Why?
This error message indicates that you are trying to run the .js file directly. You must run the .bat file, which, in turn, calls the .js logic.
There is a lot of text in the execute .js file. I don't want to do anything but run a few summaries. How can I do this?
Feel free to remove any lines of text that aren't necessary. For instance, if you just wanted to run one summary, the contents of your .js file could look like ths:
<– This app is calling Summary 50, in the Hurckes data dictionary, looking for all values in the range of 7000 and 8000.
Is Tomcat needed to run these jobs?
No, executing jobs via the Job Stream does not require Tomcat to be active.
Do I have to outline my applications in the correct order?
Yes, the Batch Stream functionality will handle all applications in a one-at-a-time method. For example, the second application will not be executed until the first one concludes.
Do I have to use your scheduler or can I use Windows Scheduler/AS400 Job Scheduler?
Either, the Job Stream functionality has been coded to allow you to do either. If you feel more comfortable with your Operating System's scheduler, you certainly can use it.
I am trying to e-mail a report. I am utilizing the authenticated e-mail option, but my e-mail is never being sent. What else do I need to configure?
First, navigate to \m-power\mrcjava\WEB-INF\classes\. Open the mrc_email.properties file. Copy the last 3 lines from this file. Paste them into mrc_email.properties after ensuring that they are not already there. Be sure to comment out the first email_host parameter. Remove the comments from the pasted in parameters and enter in the correct email_host value as well as the corresponding email_server_password for the address entered in the email_from parameter.
Secondly, edit the \m-power\mrc_execute_jobs.bat and/or your mrc_schedule_jobs.bat. Find the line that begins with "set jarlib1". At the end of this line, append:
;"C:\Program Files\Java\jre6\lib\ext"
(Note: The path to this folder may be different depending on your Operating system and or version of JRE. Please adjust accordingly).