Tip

Determine if a scheduled agent really ran during the night

VIEW MEMBER FEEDACK TO THIS TIP

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

MEMBER FEEDBACK TO THIS TIP

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.

This was first published in October 2005

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.