[Catalyst] Running Catalyst App from Command Line (or via Cron)

Ian Docherty catalyst at iandocherty.com
Fri Jan 8 16:18:01 GMT 2010

On 08/01/2010 15:58, Christoph Friedrich wrote:
> Hello there,
> I need to build a script for my catalyst application that reads some
> data and put it into the database. This script needs to run as a daily
> cron job.
> My first idea was to create a controller which handles this for me and
> use some of the other engines for catalyst (like
> Catalyst::Engine::Embeddable or Catalyst::Engine::JobQueue::POE) but I'm
> not sure if this is a good way.
It is a very common requirement, and has a simple solution.

First of all, assuming you are using something like DBIx::Class as your 
database backend you should write your database access layer totally 
separate from Catalyst, then use Catalyst::Model::DBIC::Schema to 
connect your Model in Catalyst to your database layer.

Then you can write your cron job as a perl module that just uses your 
DBIx::Class directly without the complication of Catalyst.

If you are not using DBIx::Class then you can still write your model as 
a separate module and create a very thin shim in your Catalyst model 
using Catalyst::Model::Adaptor.

This also makes testing your Models so much easier since your tests do 
not depend upon Catalyst running.

> Does someone of you have an idea how to make such a script? Maybe some
> Best Practices?

I have seen recommendations to organise your directories as follows but 
I know other people have other ideas.

lib/MyApp/DB.pm - your DBIx::Class database

lib/MyApp/Web.pm - your Catalyst App
lib/MyApp/Web/Model/DB.pm - your 'thin shim' to your MyApp::DB module


> Greets
> Christoph
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/

More information about the Catalyst mailing list