Friday, September 18, 2009

Automating a process to run every 10 minutes

If you need to run a as400 job, say a database query or report on a regular schedule, heres and example of how to do this. Lets say you needed to run a query every 10 mins...

You could submit a CL program, MYJOB to do this, to batch, with a 10 minute delay and a data area to terminate the job externally...


MYJOB:
Loop:
Run database query
Print Report
FTP data
etc

dlyjob 10 minutes
check kill dataarea and exit if set
goto loop

The problem here is that the job will could run for almost 10 minutes after, if the kill data area is set just after its checked. If you operator needs to shut down the system in a hurry you dont want him waiting an extra 10 minutes for a DLYJOB.

A better way to do the is to replace the read of a data area with a read of a data queue. The CL can then wait the required time for a kill entry to appear on the data queue. If it does you end processing runs immediately, if not you core processing runs again, then the check again. The most you will have to wait is the length of time it takes to run your core processing! So no DLYJOB required, just a QRCVDTAQ (and a QSNDDTAQ to set it of course)


MYJOB:
Loop:
Run database query
Print Report
FTP data
etc

check and wait on kill dataqueue for 10 mins and exit if set
goto loop

No comments:

Post a Comment

Post a Comment