Changeset 1488


Ignore:
Timestamp:
Feb 23, 2010, 11:21:42 PM (12 years ago)
Author:
mitchb
Message:
Various tweaks to rails autoreloading code

o Don't watch all of public, as apps may cache files there and cause
  the fcgi to repeatedly die and destroy any fcgi performance gains
o Specifically watch .htaccess and dispatch.fcgi
o Raise an error to die instead of trying to reload code and dying
  in the process because you can't
o Explain that killing the fcgi process results in a reload of the code
  at the next request
(Merge of r1411:1486 from branches/locker-dev to trunk, originally from gdb)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/locker/deploy/bin/rails

    r1427 r1488  
    130130
    131131t2 = Thread.new do
    132    # List of directories to watch for changes before reload
    133    Thread.current[:watched_dirs] = ['app', 'config', 'db', 'lib', 'public']
     132   # List of directories to watch for changes before reload.
     133   # You may want to also watch public or vendor, depending on your needs.
     134   Thread.current[:watched_dirs] = ['app', 'config', 'db', 'lib']
     135
     136   # List of specific files to watch for changes.
     137   Thread.current[:watched_files] = ['public/dispatch.fcgi',
     138                                     'public/.htaccess']
    134139   # Sample filter: /(\.rb|\.erb)\$/.  Default filter: watch all files
    135140   Thread.current[:watched_extensions] = //
     
    169174     Thread.current[:modifications] = {}
    170175     Thread.current[:iterations] = 0
    171      RailsFCGIHandler.reload!
     176     # This is a kludge, but at the same time it works.
     177     # Will kill the current FCGI process so that it is reloaded
     178     # at next request.
     179     raise RuntimeError
    172180   end
    173181
     
    175183   # Wait until the modify time changes, then reload.
    176184   while true
    177      reload if Thread.current[:watched_dirs].inject(false) {|z, dir| z || modified_dir(File.join(File.dirname(__FILE__), '..', dir))}
     185     dir_modified = Thread.current[:watched_dirs].inject(false) {|z, dir| z || modified_dir(File.join(File.dirname(__FILE__), '..', dir))}
     186     file_modified = Thread.current[:watched_files].inject(false) {|z, file| z || modified(File.join(File.dirname(__FILE__), '..', file))}
     187     reload if dir_modified || file_modified
    178188     Thread.current[:iterations] += 1
    179189     sleep 1
Note: See TracChangeset for help on using the changeset viewer.