|
|
|
|
|
|
|
|
|
|
|
|
|
|
Control your application's agents with this Agent Launchers tool (continued)
Launching agents on the specified schedule
Having a nice interface for specifying schedules is important, but it's useless without a mechanism to actually make the agents run on schedule. Essentially, this mechanism needs to be a server task that periodically checks to see which enabled agents are new or scheduled to run, runs them, and then marks them so that they won't run again before the next scheduled time. Instead of a true server task, however, it is sufficient to use a scheduled agent that runs more frequently than the smallest schedulable interval; that is, a launcher agent that runs more than once per hour. To use a round number, I chose to make this agent (agtschAGTLauncher) run every 30 minutes.
Note: When one scheduled agent launches another agent, the second agent runs under its own authority--that is, with whatever permissions its signer has. You should make sure that both the launcher and all schedulable agents are signed appropriately.
The code for the launcher agent is contained in the slAGTLauncher script library, in the subLaunch routine. Essentially, it loops through all enabled agent schedules, checks each one's schedule, and launches the ones whose schedules currently allow them to be launched. The code for subLaunch is straightforward and is omitted here.
To check a given agent schedule, the subLaunch routine calls the fnIsScheduled function, which is the core piece of the whole auto-launch mechanism. Instead of listing out the code or explaining the functionality in prose, I think the function's process can best be understood through pseudocode:
fnIsScheduled (Schedule As Document)
bRunAgent = False 'Assume the worst
dtLastRan = Schedule.LastLaunched 'the last time the agent was launched
If (dtLastRan = "") Then bRunAgent = True
If (dtLastRan = Today) Then bRanToday = True
If Not(bRunAgent) and (Now > Schedule.ScheduledTime) then
'We don't yet know whether to run the agent, but the designated time has arrived.
If Not (bRanToday) Then
'The agent has not yet been launched today.
Select Case Schedule.Frequency
Case "monthly"
If (the agent hasn't been run in 31 days) Then
bRunAgent = True
Else
If Schedule.MonthDay = "Last" Then
If (Today is last day of the month) Then bRunAgent = True
Else
If (Today = Schedule.MonthDay) Then bRunAgent = True
End If
End If
Case "weekly"
If (the agent hasn't been run in a week) Then
bRunAgent = True
Else
If (Today is the scheduled day) Then bRunAgent = True
End If
Case "daily"
'It's time, and the agent hasn't been run yet today
bRunAgent = True
Case "hourly"
'It's time, and the agent hasn't been run yet today
bRunAgent = True
End Select
Else
'The agent has already been run today.
If (Schedule.Frequency = "hourly") Then
TimeDifference = Now - dtLastRan
If (TimeDifference > Schedule.SpecifiedInterval) Then bRunAgent = True
End If
End If
End If
Return bRunAgent
End Function 'fnIsScheduled
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Advertisement --
Sophisticated Meets Simple For Document Management
Share. Control. Manage.
Documents, emails, and content in the context of how work is done.
Native to Lotus Domino. The User Experience unseen for Lotus Domino.
Do more with less. Really.
See the possibilities Docova unleashes for Lotus Domino. |
-- Advertisement --
Mark your calendar for in-depth Lotus training, May 12-14, Boston
Join experts and peers May 12-14 in Boston for educational and networking events that deliver real-world Lotus training so you can increase productivity and efficiency in your company, advance your skills, and squeeze the most from your current environment. One registration gets you into THE VIEW's Admin2010 and Lotus Developer2010.
Register by April 10 to save $200. |
|
|
|
|
|
|
|
|
|
|