Determine if a scheduled agent really ran during the night
This agent checks to make sure that critical agents scheduled to run overnight did, in fact, run.
We write a lot of critical logic into agents that are scheduled to run during the night. Sometimes agents don't run. Perhaps the administators turned down the server, changed access rights or someting else happened that stopped the agent for a night or more.
I created an application that stored contracts. To every contract the users can add dates when different parts of the contract ends and they need to preform some kind of action not to be forced into an expensive extension of the contract or miss out on some other benefits.
So a scheduled agent takes care of all the logic. Sending out e-mails to the responsible parties of every contract in good time before the last date of action is reached. But what if the agent doesn't run? Then the key function of my appliction doesn't deliver. So I did the following: In the database post open event (well hidden as other - database resources - database script) I check to see if the agent that should have been running this night really did run. Every time a user opens the database, the application checks to see if it is working as expected. No magic in the code but it makes the application more stable.
Sub Postopen(Source As Notesuidatabase) Dim session As New NotesSession Dim db As NotesDatabase Dim agent As NotesAgent Dim vLastRun As Variant Dim docConfig As NotesDocument Dim docMail As NotesDocument Dim body As NotesRichTextItem Dim strSenastKord As String On Error Goto errorhandler Set db = session.CurrentDatabase Print "Opening " + db.Title If db.Server <> "" Then Set agent = db.getAgent ("agBevakning") Dim datLastRun As New NotesDateTime(agent.LastRun) If Today = datLastRun.DateOnly Then Print "Agent ran ok" Else Messagebox "Message to the user that explains what has not happend and to take the right actions to correct the problem, i.e. call support and manually check the view that lists all up comming events" End If Else Print "Database is local, can't check if the agent has run on the server" End If Exit Sub errorhandler: Print "Can't check to see if the agent has run." Resume Next End Sub
This code works great, and I've used it as an easy way to have a single code set that can be scheduled to run in different environments with minimal fuss. Before you get too confident in this, though, check on what happens when your called agent exceeds the runtime limits for the server.
—B. Hawthorne
******************************************
Yes, you are right. If the agent exceeds the runtime limit, some work might not be done, but the script reports nothing. In my case, this is unlikely since the agent really hasn't that much to do and we allow quite a long agent runtime during the night. An enhancement is to read the agent log and log success or failure to the log, as well as check for that in the script above.
—Erik Rydberg, tip author
Do you have comments on this tip? Let us know.
This tip was submitted to the SearchDomino.com tip exchange by member Erik Rydberg. Please let others know how useful it is via the rating scale at the end of the tip. Do you have a useful Notes/Domino tip or code to share? Submit it to our bimonthly tip contest and you could win a prize and a spot in our Hall of Fame.