[Catalyst] [RFC] C::P::Scheduler - cron-like scheduling of events
Brandon Black
blblack at gmail.com
Wed Dec 14 20:19:23 CET 2005
On 12/12/05, Yuval Kogman <nothingmuch at woobling.org> wrote:
> On Sun, Dec 11, 2005 at 23:01:24 -0500, Andy Grundman wrote:
> > I have a need for a simple scheduling plugin to do things like clean up database sessions, so I roughed out docs
> > for a new plugin called Scheduler. If you've got any thoughts or suggestions, please let me know. :)
>
> There are a bunch of cron scheduler thingies on the CPAN, i think we
> should use one of them instead of rolling our own.
>
> Also, how does it get initiated?
>
> I was thinking the simplest way to run it is via a cron script, and
> the catalyst scheduler thing just checks if it needed to do
> something between the last invocation and this one.
>
> This does not contradict:...
>
> > Depending on the level of traffic to the application, events may or may
> > not run at exactly the correct time, but it should be enough to satisfy many
> > basic scheduling needs.
>
> This seems to imply that it runs after finalize if needed... How
> does this work with respect to long running jobs?
>
> I think we should support both invocation styles.
Running cron jobs from within mod_perl, for instance, is problematic
because it has to check for times during finalize() or some other
request-initiated thing, and if the cron-task in question does in fact
have a long run-time, that's bad. If I were to schedule a cronjob for
4:00AM, and on a particular night nobody used my application from
3-7AM, the job would likely get run at 7AM. And if that task took an
hour to complete, at the very least a mod_perl child is tied up for an
hour. I would imagine under some Engines it could turn into a much
worse thing.
I could set up a real cron job to hit the front page of my webserver
once an hour just to kick the Cat app in the head and make sure the
cat-cron jobs get run, but then I've gone and used the system's cron
anyways, so why bother?
A potential solution would be to make a seperate perl-based generic
cron daemon which can run independant of the Catalyst Engine from
scripts/ (let's call it catcron.pl), and have the Engine or something
else early in the startup process decide when and how to fire it up
and shut it down (fork/exec it on startup before children are spawned,
send it a kill signal on shutdown). The ->config() or ->schedule()
data that's available statically at App start time could be written to
a crontab file that catcron.pl reads on startup.
Dynamic scheduling based on Controller events could update this
crontab file with new entries (catcron.pl would have to watch the
crontab mtime periodically). You could invent additions to the
crontab spec to allow for one-shot events as well as periodic ones.
Just rambling thoughts on the matter.
-- Brandon
More information about the Catalyst
mailing list