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

Jon Schutz jon+catalyst at youramigo.com
Tue Apr 12 00:05:40 GMT 2011



On 12/04/11 08:10, Charlie Garrison wrote:
> Good morning,
>
> On 11/04/11 at 9:20 PM +0930, Jon Schutz <jon+catalyst at youramigo.com>
> wrote:
>
>> That was my thought.  Usage is essentially...
>>
>> use strict;
>> use warnings;
>> use HTTP::Request;
>>
>> BEGIN {
>> $ENV{CATALYST_ENGINE} = 'Embeddable';
>> }
>>
>> require MyApp;
>> my $response;
>> MyApp->handle_request(HTTP::Request->new('GET',
>> 'http://localhost/send/email'), \$response);
>
> Thanks for clarifying. And other than not tying up a FastCGI process,
> what is the advantage of that approach over just sending a request via
> http?
>

Depends on your circumstances, and personally I'd probably take the
approach of divorcing the templates from the catalyst context and just
use TT outside of Catalyst.  But potential advantages of the embedded
approach are:

* Not needing to expose private URLs - if the URL you need to hit to
generate the email is not supposed to be available to the outside world,
you can use a different configuration for the app controlled from the
cron job.
* Still works if your Apache/FastCGI happen to be not running, in the
midst of restarting, or in bad shape for whatever reason, so save a
range of error checking and recovery that you would otherwise have to do.
* Can send your emails from another machine even if you don't have an
app running there.

BTW, you can use whichever form of URL that you like in the embedded
request - all of these forms that I tried still work (though as Matthias
pointed out, may affect how URLs appears in your templated output):

http://my.domain.com/send/email
http:///send/email
/send/email

-- 

Jon Schutz
http://notes.jschutz.net/






More information about the Catalyst mailing list