开发者

SQL doesn't get executed in production under Phusion Passenger

I have a code similar to the following:

class TheClass < ActiveRecord::Base
  connection.execute "set language 'us_english'"
  // the rest of the code
end

The execute command doesn't get executed in production under Passenger! Using Mongrel it's ok, putting the code inside a later called function works, Passenger+development settings also works.

Is there something different in the way Passenger开发者_C百科 deals with the connection or the Class instanciation that I'm not aware?

Edit:

It's clear that it's the way Passenger makes connections. So the question boils down to "Is there a supported way to execute a SQL statement when a connection is stablished?"


My psychic debugging says you're being bitten by Passenger's forking model.

Basically, Passenger forks a bunch of worker processes off a main process, which already has your rails environment loaded. This reduces the amount of time it takes the workers to initialize, since all your model, controller etc. classes are already there.

Now, from the Passenger documentation:

Note that Phusion Passenger automatically reestablishes the connection to the database upon creating a new worker process, which is why you normally do not encounter any database issues when using smart spawning mode.

Your connection.execute statement runs when the TheClass is loaded. This actually only happens once, in the parent process that's forking all the workers. The workers each establish their own connections, but never run your 'set language' query since TheClass is already loaded. It works in dev mode because that reloads your classes every time.

There might be some sort of setup you can do in application.rb to tell ActiveRecord your connection language, otherwise you'll probably have to do an ugly hack of running that query in a before_filter or something.


check your passenger error logs, these may be different from the standard rails log files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜