FAQ
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.
Does someone of you have an idea how to make such a script? Maybe some
Best Practices?

Greets
Christoph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: christoph.vcf
Type: text/x-vcard
Size: 147 bytes
Desc: not available
Url : http://lists.scsys.co.uk/pipermail/catalyst/attachments/20100108/b419f61e/christoph.vcf

Search Discussions

  • Stuart Watt at Jan 8, 2010 at 4:15 pm
    I always liked the solution used by Drupal of simply making cron use
    curl/wget/... to request a special URL. Then it becomes an action and is
    easy to code and configure almost on any platform.

    Long-running tasks (beyond that of an HTTP request) are a different
    matter. At present, we do this with our own task manager, which is
    basically nothing to do with Catalyst -- although it shares the code
    under the Catalyst model components. This creates the data needed by the
    app. This can take as long as it likes. We then have a quick switch,
    which updates the config and prods the web server to recycle its worker
    processes.

    It probably depends if you are adding data more or less monotonically to
    the current app, or more radically changing it. If it is a radical
    change to the data, I'd guess you'd need to close everything down
    cleanly and restart.

    All the best
    Stuart


    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.
    Does someone of you have an idea how to make such a script? Maybe some
    Best Practices?

    Greets
    Christoph

    --
    This message was scanned by ESVA and is believed to be clean.
    Click here to report this message as spam.
    http://antispam.infobal.com/cgi-bin/learn-msg.cgi?id27432806D.62AD5



    _______________________________________________
    List: Catalyst@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/
  • Nick Perez at Jan 8, 2010 at 4:16 pm

    On Fri, 08 Jan 2010 16:58:06 +0100 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.
    Does someone of you have an idea how to make such a script? Maybe
    some Best Practices?

    Greets
    Christoph

    If the script is running independent of catalyst (cron job) why does it
    need to involve your application. Assuming you are using DBIx::Class,
    you can use your Schema and associated Result[Set] classes or even your
    true domain objects (those are separate from your app right?) to
    accomplish this without shoe horning in catalyst.

    --

    Nicholas Perez
    XMPP/Email: nick@nickandperla.net
    http://search.cpan.org/~nperez/
    http://github.com/nperez
  • Ian Docherty at Jan 8, 2010 at 4:18 pm

    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
    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
    lib/MyApp/Web/View
    lib/MyApp/Web/Controller

    Regards
    Ian
    Greets
    Christoph



    _______________________________________________
    List: Catalyst@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/
  • Jay Shirley at Jan 8, 2010 at 4:20 pm

    On Fri, Jan 8, 2010 at 7:58 AM, 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.
    Does someone of you have an idea how to make such a script? Maybe some Best
    Practices?

    Greets
    Christoph

    I would create a standalone perl class that does everything you need,
    then in your Catalyst app just implement a thin adapter using
    something like Catalyst::Model::Adapter (or
    Catalyst::Component::InstancePerContext).

    I wouldn't bother with Catalyst in the crontab, instead just
    instantiate this model and have it do what needs done.

    -J

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcatalyst @
categoriescatalyst, perl
postedJan 8, '10 at 3:58p
activeJan 8, '10 at 4:20p
posts5
users5
websitecatalystframework.org
irc#catalyst

People

Translate

site design / logo © 2022 Grokbase