Ignore:
Timestamp:
Jan 8, 2010, 2:15:22 AM (14 years ago)
Author:
gdb
Message:
Changed rails reloader script to reload if a new file is created.  Have tested this on a toy app.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/locker-dev/locker/deploy/bin/rails

    r1408 r1410  
    130130
    131131t2 = Thread.new do
    132    # List of directories to watch for changes before reload
    133132   Thread.current[:watched_dirs] = ['app', 'config', 'db', 'lib', 'public']
    134    # Sample filter: /(\.rb|\.erb)\$/.  Default filter: watch all files
    135133   Thread.current[:watched_extensions] = //
     134   # Iterations since last reload
     135   Thread.current[:iterations] = 0
    136136
    137137   def modified(file)
    138      mtime = File.stat(file).mtime
    139      Thread.current[:modifications][file] ||= mtime
    140      Thread.current[:modifications][file] != mtime
     138     begin
     139       mtime = File.stat(file).mtime
     140     rescue
     141       false
     142     else
     143       if Thread.current[:iterations] == 0
     144         Thread.current[:modifications][file] = mtime
     145       end
     146       Thread.current[:modifications][file] != mtime
     147     end
    141148   end
    142149
    143    # Don't symlink yourself into a loop.  Please.
     150   # Don't symlink yourself into a loop.  Please.  Things will still work
     151   # (Linux limits your symlink depth) but you will be sad
    144152   def modified_dir(dir)
    145153     Dir.new(dir).each do |file|
     
    150158       else
    151159         return true if Thread.current[:watched_extensions] =~ absfile &&
    152            modified(absfile)
     160           modified(absfile)
    153161       end
    154162     end
     
    158166   def reload
    159167     Thread.current[:modifications] = {}
     168     Thread.current[:iterations] = 0
    160169     RailsFCGIHandler.reload!
    161170   end
     
    164173   # Wait until the modify time changes, then reload.
    165174   while true
    166      reload if Thread.current[:watched_dirs].inject(false) {|z, dir| z ||
    167        modified_dir(File.join(File.dirname(__FILE__), '..', dir))}
     175     reload if Thread.current[:watched_dirs].inject(false) {|z, dir| z || modified_dir(File.join(File.dirname(__FILE__), '..', dir))}
     176     Thread.current[:iterations] += 1
    168177     sleep 1
    169178   end
Note: See TracChangeset for help on using the changeset viewer.