
moseley at hank
Aug 27, 2009, 7:58 PM
Post #3 of 6
(1341 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/
|