Shelby Westman wrote:
>I have deployed a Rails app that runs under lighttpd and is using an
>Active Record session store. Scott Barron kindly provided me with a
>short Ruby script (quoted below) that will periodically sweep the
>database clean of stale sessions based upon a period of inactivity.
>
>When deploying this script, it creates a Session object. This script
>apparently looks at the environment.rb file to determine the
>RAILS_ENV. I say this, because when I tried to specify the
>''production'' environment in the script, it said that it
was already
>defined in environment.rb.
>
>However, when called from this script, environment.rb thinks that the
>environment is development, even though lighttpd is running the rails
>in production mode. (The database is not even defined for development
>in database.yml, so I know that it is running in production mode).
>
>The little script is picking up its ''development''
assumption from this
>line in environment.rb:
>RAILS_ENV = ENV[''RAILS_ENV''] ||
''development''
>
>When I changed the ''development'' to
''production'' in this script, it
>runs fine. My question is, why does the environment.rb script not
>pick up that rails is running in production mode, when called from
>this script?
>
>Shelby
>_____________
>
>#!/usr/local/bin/ruby
>require File.dirname(__FILE__) + ''/../config/environment''
>SESSION_TIMEOUT = 30.minutes
>class Session < ActiveRecord::Base
>end
>stale = Session.find(:all, :conditions => ["updated_at <=
?", Time.now
>- SESSION_TIMEOUT])
>stale.each { |s| s.destroy }
>
>
>
Just add ENV[''RAILS_ENV'']=''production''
before the require. That should
work. Or pass it as an argument to your script:
ENV[''RAILS_ENV''] =
ARGV[0] || ''production''
Hope that helps.
-- stefan