[Catalyst] Suggestions for sending email from cron job using'Catalyst' templates?

Charlie Garrison garrison at zeta.org.au
Mon Apr 11 23:50:39 GMT 2011

Good morning,

On 11/04/11 at 6:58 PM +0300, Octavian Rasnita 
<orasnita at gmail.com> wrote:

>The TT templates used by the Catalyst app might contain many things
>like c.user, c.uri_for_action, may display images, may depend on other
>templates which are loaded automaticly when those templates are
>specified in the app config file. So there is no sane way of using
>those wrapper templates for sending email from a cron job.

That was the conclusion I was reaching; I wanted feedback from 
others before I tried to make my own garden path.

>....so you'll need to make a web request in order to have the same
>context variable and it would affect much the performance if you'll
>load the Cat app just for sending email. You can do it this way, but...
>it isn't a way I prefer to do this thing.

Being a daily cron job, loading the app once isn't too much of 
an issue. But I couldn't really see what the advantage was 
either. All my other cron jobs have been able to use models only 
(DBIC), and I was thinking I could just use TT outside Catalyst 
as well, but I hadn't thought through all the ctx dependancies 
in the templates.

>Whenever you will find that a template used in the Cat app can't be
>used in a cron job, split that template into smaller templates, and for
>the templates that use the Catalyst context create another version that
>doesn't use it. Then make a template that include those templates which
>work in the Cat app and another template that works in the cron job.

Or find all uses of ctx in the templates and supply sane values 
(or methods) in template_vars to replace the standard Catalyst 
ctx. That seems like a maintenance nightmare though.

>If there are too many parts of the template that needs to be changed,
>it is a better idea to create a separate entire template for using it
>in the external program.

I'll consider this idea. Since it's just email templates they 
are not as complex. I'm not sure what the benefit will be 
though. Except for not having to take a FastCGI process, I can't 
see what the benefit of a 'smart' cron job is. I may as well 
just send a http request to the app.

I seem to recall a few cron/schedule packages to use within Cat 
apps. The only one I can find right now is 
Catalyst::Plugin::Scheduler, which I don't really care for since 
it just piggybacks on user requests. Can anyone suggest any others?

>The alternative of sharing the templates among the Cat app and other
>external program would involve using templates that don't depend on the
>Catalyst app, and this can be done easily, but we would miss many
>features offered by the Catalyst context, and we probably need to share
>too few templates to prefer to lose those features.

Yep, I agree. I can certainly do it all outside Cat context, but 
not sure it's worth the maintenance headache. So unless someone 
else comes up with clever suggestion I'll just move all the 
logic to a controller action.

Which just leaves whether to use a scheduler within Catalyst, or 
just have a cron job send a request. Are there any best 
practices for that I should be aware of?


    Ꮚ Charlie Garrison ♊ <garrison at zeta.org.au>

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
〠  http://www.ietf.org/rfc/rfc1855.txt

More information about the Catalyst mailing list