[Catalyst] Connect DBIx::Class model on startup?

Daniel J. Luke dluke at geeklair.net
Mon Mar 5 15:01:17 GMT 2012


On Mar 5, 2012, at 3:15 AM, Tomas Doran wrote:
> On 5 Mar 2012, at 02:30, Daniel J. Luke wrote:
>> On Mar 4, 2012, at 9:56 AM, Tomas Doran wrote:
>>> On 2 Mar 2012, at 20:44, Daniel J. Luke wrote:
>>>> On Feb 25, 2012, at 10:00 AM, Daniel J. Luke wrote:
>>>>> On Feb 25, 2012, at 3:39 AM, Tomas Doran wrote:
>>>>>>>> Or maybe there's a reason why there's not an obvious hook and someone can point me to the pitfalls I'm not seeing.
>>>>>> 
>>>>>> It's not totally obvious as you can't do this at process startup (as you then fork!),
>>>>> 
>>>>> Yeah, I just realized that that was going to be an issue when I went to attempt this (late yesterday).
>>>>> 
>>>>>> so it has to be done in the FCGI process manager really (which does the forking)…
>>>>>> 
>>>>>> You can subclass FCGI::ProcManager and implement:
>>>>>> 
>>>>>> sub handling_init {
>>>>>> my $self = shift;
>>>>>> $self->next::method(@_);
>>>>>> MyApp->model('DB')->schema->dbh->ping; # Check we have a DB connection that's working straight after forking but before starting to handle requests.
>>>> 
>>>> Maybe I'm being thick, but where does that instance of MyApp come from? I don't see it being passed into FCGI::ProcManager
>>> 
>>> What instance of MyApp?
>> 
>> the one that I'm going to call ->model() on in order to pre-connect to my DB?
> 
> Erm? Where did I suggest that?

you didn't, when it didn't work, I assumed that there was just a missing sigil in what you pasted (that's why I figured I was being thick ;-) ).

> (I didn't - I suggested calling a class method, which ->model is…)
> 
>>> There is no instance?
>> 
>> Then there's some magic that I'm missing? If I take your code literally, I'm going to get a 'cannot use a string as a hash ref' error.
> 
> Did you try this already?

yes:
FastCGI: manager (pid 18350): server (pid 19242) started
Can't use string ("MyApp") as a HASH ref while "strict refs" in use at /path/to/lib/vendor_perl/5.12.2/Class/Accessor/Fast.pm line 10.

> Unless you've specifically done something to break how things normally work, then it'll work fine.


I don't think I've done anything unusual.

perl 5.12.2
Class::Accessor::Fast 0.34
Catalyst 5.80031
--
Daniel J. Luke                                                                   
+========================================================+                        
| *---------------- dluke at geeklair.net ----------------* |                          
| *-------------- http://www.geeklair.net -------------* |                          
+========================================================+                        
|   Opinions expressed are mine and do not necessarily   |                          
|          reflect the opinions of my employer.          |                          
+========================================================+






More information about the Catalyst mailing list