Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Catalyst: Users

Handling configuration outside the Catalyst application

 

 

Catalyst users RSS feed   Index | Next | Previous | View Threaded


daniel.austin at gmail

Aug 27, 2009, 7:10 PM

Post #1 of 6 (1478 views)
Permalink
Handling configuration outside the Catalyst application

Hello

How are you handling configuration for applications or code that run
outside of Catalyst?

For example, in my model tests, I have code like this:

use MyCompany::CatApp;
my $app = MyCompany::CatApp->new();
my $model = $app->model('DB::Model')->new({});
ok( $model->insert );

etc.

This way the model tests are talking to the right database as
configured for that environment. But it seems slow to run and it's not
the right coupling if I have, say, a cronjob that wants to use the
same models.

Are there any patterns anyone can recommend?

Dan

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


edencardim at gmail

Aug 27, 2009, 7:36 PM

Post #2 of 6 (1384 views)
Permalink
Re: Handling configuration outside the Catalyst application [In reply to]

On Thu, Aug 27, 2009 at 11:10 PM, Daniel Austin<daniel.austin [at] gmail> wrote:
> Hello
>
> How are you handling configuration for applications or code that run
> outside of Catalyst?
>
> For example, in my model tests, I have code like this:
>
>    use MyCompany::CatApp;
>    my $app = MyCompany::CatApp->new();
>    my $model = $app->model('DB::Model')->new({});
>    ok( $model->insert );
>
> etc.
>
> This way the model tests are talking to the right database as
> configured for that environment. But it seems slow to run and it's not
> the right coupling if I have, say, a cronjob that wants to use the
> same models.
>
> Are there any patterns anyone can recommend?

Catalyst::Model::DBIC::Schema is just an adaptor for loading a
DBIC::Schema inside a catalyst application. You can "use
MyApp::Schema::DB" anywhere outside your catalyst application, see
DBIx::Class::Schema for how to connect your schema to a database
backend without the help of C::M::DBIC::Schema.

Besides that, I've just finished writing code for $work that does a
few hacks to use Catalyst::Plugin::ConfigLoader outside the context of
a catalyst application. it's a temporary solution, my opinion is that
there should be an external module for use by any application, not
just cat, and the plugin should just hook that module into Catalyst.

--
Eden Cardim Need help with your Catalyst or DBIx::Class project?
Code Monkey http://www.shadowcat.co.uk/catalyst/
Shadowcat Systems Ltd. Want a managed development or deployment platform?
http://edenc.vox.com/ http://www.shadowcat.co.uk/servers/

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


moseley at hank

Aug 27, 2009, 7:58 PM

Post #3 of 6 (1373 views)
Permalink
Re: Handling configuration outside the Catalyst application [In reply to]

On Thu, Aug 27, 2009 at 7:10 PM, Daniel Austin <daniel.austin [at] gmail> wrote:
>
> Hello
>
> How are you handling configuration for applications or code that run
> outside of Catalyst?
>
> For example, in my model tests, I have code like this:
>
>    use MyCompany::CatApp;
>    my $app = MyCompany::CatApp->new();
>    my $model = $app->model('DB::Model')->new({});
>    ok( $model->insert );
>
> etc.
>
> This way the model tests are talking to the right database as
> configured for that environment. But it seems slow to run and it's not
> the right coupling if I have, say, a cronjob that wants to use the
> same models.
>
> Are there any patterns anyone can recommend?

I have a config module that I use everywhere.  I specify a running
"mode", such as testing, staging, and production so that the correct
config is pulled.

$ script/dump_config.pl --mode=production log4perl
{
enable => 1,
level => "info",
}

$ script/dump_config.pl --mode=development log4perl
{
enable => 1,
level => "debug",
}

Catalyst uses a plugin for that module. I also have another module
that uses that configuration class. It makes it easy to write cron
scripts.

#!/usr/bin/perl
use App::ConfigUtil;

# define options for this script
my %options = (
minutes_old => {
help => 'Items must be "minutes_old" to be removed"
format => '=i',
default => 60,
},
);


my $app = App::ConfigUtil->new( \%options );
my $config = $app->config; # same config Catalyst sees
my $db = $app->database;

$app->lock(20); # lock this cron job for 20 seconds (since running on
multiple servers)

$db->model( 'Foo' )->remove_old;

Then it's just ./clean_foo --mode=production --minutes_old=120



But, now I'm thinking about making all access go through Catalyst.
That is, a cron job would log in via the API and then use and API
method to do its work. Wouldn't need to be a web request, of course.
Then I've got one access layer to the application and can have ACL
rules for the cron user and unified logging.


--
Bill Moseley
moseley [at] hank

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


mdietrich at cpan

Aug 28, 2009, 1:10 AM

Post #4 of 6 (1360 views)
Permalink
Re: Handling configuration outside the Catalyst application [In reply to]

Hi,

Am 28.08.2009 um 04:58 schrieb Bill Moseley:

> But, now I'm thinking about making all access go through Catalyst.
> That is, a cron job would log in via the API and then use and API
> method to do its work. Wouldn't need to be a web request, of course.
> Then I've got one access layer to the application and can have ACL
> rules for the cron user and unified logging.

has someone used Catalyst::Plugin::CommandLine for this or similar?
Of course this is not a module for accessing catalyst from outside
(like via API), but it is to control Catalyst from a script. And it
starts the app everytime the script runs...

matt

--
rainboxx Matthias Dietrich
Freier Software Engineer

rainboxx | Tel.: +49 (0) 151 / 50 60 78 64
Tölzer Str. 19 | Mail: matt [at] rainboxx
70372 Stuttgart | WWW : http://www.rainboxx.de

XING: https://www.xing.com/profile/Matthias_Dietrich18
GULP: http://www.gulp.de/profil/rainboxx.html
Attachments: PGP.sig (0.19 KB)


willert at gmail

Aug 28, 2009, 3:22 AM

Post #5 of 6 (1376 views)
Permalink
Re: Handling configuration outside the Catalyst application [In reply to]

On Fri, 2009-08-28 at 12:10 +1000, Daniel Austin wrote:
> Hello
>
> How are you handling configuration for applications or code that run
> outside of Catalyst?
>
> [snip]

If you are just trying to emulate Catalyst's config loading mechanism to
connect the schema yourself then have a look at Config::JFDI on CPAN, it
does (or at least advertises to do) exactly what you want.

Hint: maybe use Catalyst::Utils for appprefix and home

HTH,
Sebastian


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


daniel.austin at gmail

Aug 29, 2009, 9:10 PM

Post #6 of 6 (1331 views)
Permalink
Re: Handling configuration outside the Catalyst application [In reply to]

2009/8/28 Eden Cardim <edencardim [at] gmail>:
> > [...]
> Catalyst::Model::DBIC::Schema is just an adaptor for loading a
> DBIC::Schema inside a catalyst application. You can "use
> MyApp::Schema::DB" anywhere outside your catalyst application, [...]

Initially I was doing exactly that for my model tests. But then I
found myself hacking in a partial implementation of Catalysts
ConfigLoader so that the model tests would talk to the correct
database depending on whether or not they were running in the "dev",
"test" or "cI" (continuous integration) environments. That seemed
wrong so I switched to loading the full Catalyst app just to get the
correct config (which also seems wrong... :-) but I digest).

> [...] my opinion is that
> there should be an external module for use by any application, not
> just cat, and the plugin should just hook that module into Catalyst.

That sounds much cleaner. Sounds like others (Bill, Sebastian)
advocate a similar approach. I'll take a look at Config::JFDI as
suggested by Sebastian in this thread.

Thanks everyone.

Dan

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

Catalyst users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.