[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Perl: CmdSchedule
This email is primarily directed towards Aaron, but the group is
encouraged to look over it, and if any of you are interested in helping do
this, contact Aaron.
CmdSchedule:
The purpose of the table now in the linuxkb database called CmdScedule is
to allow the forming directory and php interfaces to easily
schedule external commands, and easily interact with non php code. I
encourage you to look at the CmdSchedule table while reading this.
How I think it should work is:
Every minute a perl script will query the CmdSchedule table to see if
there are any commands to be executed. If there are, the perl script will
call those commands, passing object ID's as parameters of those commands.
You'll notice the table closely resembles crontab. In addition to
allowing an easy way for the objects to schedule outside tasks, etc. buy
taking this approach we allow ourselves to improve this perl script once
working, in order to allow it to optimize execution. For example... If
evberything were to be done immediatly instead of scheduled... you may
have this situation:
10 people logged on all submitting questions that are to be processed and
mailed out via the mail connector, as well as posted via the web. This
involves 10 processes to do the mailing all unaware of each other, 10
submits, etc.
If we do this via scheduling, all 10 get logged into the CmdSchedule table
as immediate actions, and when the query is run, it will see 10 identical
actions... instead of forking 10 processes, it can just combine the
targeted objects and pass them as 10 parameters into the mailer.
Thats just one example - there's a ton more we could eventually do to
optimize things... but for now - we just need to get it working. So -
here is the SQL command to identify what commands are to br run now (at
the minute the perl script runs):
select CmdID, CmdType, CommandPath, TargetObjects, Attempts from
CmdSchedule,
ExternalCommands where CmdSchedule.CommandID = ExternalCommands.CommandID
and (Status != 'Disabled' and Status !='Failed' and Status != 'Running')
and ( (CmdType = 'Immediate' OR Status = 'PendingRetry') OR ( (Hour = '*'
OR Hour = 'this hour') AND
(Minute = '*' OR Minute = 'this minute') AND (WeekDay = '*' OR WeekDay =
'this day of week') AND (MonthDay = '*' OR MonthDay = 'this dat of month')
) );
You'll need to come up with ways to do various things... but I'm designing
the whole thing... so... if ya run into sql issues lemme know.
I was thinking after the select, when you have your list of commands, you
should update the table and set matching CmdID's to a status of 'Running'.
If a command fails for any reason you would increment the Attempts by 1,
and set staus to 'PendingRetry'. The sql statement above would always
return record's who's CmdType is immediate or status is PendingRetry
regardless of scheduled time.
Once Attempts count hits 3 or whatever, it should be set to Status =
'Failed' which will stop it from being returned. Later we can worry about
a way to notify ourselves of failures, and how frequently they'll be
purged.
Don't know if I left anything out... please mail me if I have.
Obviously, the command you'll call will be contained in the CommandPath
field, and TargetObjects will be passed to that command as parameters.
I'll be doing the php code to poulate this table... perl just has to read
it and do what it says... any other thoughts?
They're very welcome...
--
Jason
http://vodka.linuxkb.org/~chardros