Replace directory_watcher with listen.
Directory_watcher consumed ~25% CPU on big Jekyll projects (depending on the number of watched files), since it polled for changes every second. Listen is easier on CPU, as it uses directory change notifications provided by OS (currently OS X and Linux), falling back to polling when they are not available.
This commit is contained in:
parent
35336bfff4
commit
8fe25a6958
|
@ -25,7 +25,7 @@ Gem::Specification.new do |s|
|
|||
|
||||
s.add_runtime_dependency('liquid', "~> 2.5.2")
|
||||
s.add_runtime_dependency('classifier', "~> 1.3")
|
||||
s.add_runtime_dependency('directory_watcher', "~> 1.4.1")
|
||||
s.add_runtime_dependency('listen', "~> 1.3.1")
|
||||
s.add_runtime_dependency('maruku', "~> 0.5")
|
||||
s.add_runtime_dependency('pygments.rb', "~> 0.5.0")
|
||||
s.add_runtime_dependency('commander', "~> 4.1.3")
|
||||
|
|
|
@ -31,25 +31,24 @@ module Jekyll
|
|||
#
|
||||
# Returns nothing.
|
||||
def self.watch(site, options)
|
||||
require 'directory_watcher'
|
||||
require 'listen'
|
||||
require 'pathname'
|
||||
|
||||
source = options['source']
|
||||
destination = options['destination']
|
||||
destination = Pathname.new(options['destination'])
|
||||
.relative_path_from(Pathname.new(source))
|
||||
.to_path
|
||||
|
||||
Jekyll.logger.info "Auto-regeneration:", "enabled"
|
||||
|
||||
dw = DirectoryWatcher.new(source, :glob => self.globs(source, destination), :pre_load => true)
|
||||
dw.interval = 1
|
||||
|
||||
dw.add_observer do |*args|
|
||||
Listen.to(source, :ignore => %r{#{Regexp.escape(destination)}}) do |modified, added, removed|
|
||||
t = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print Jekyll.logger.formatted_topic("Regenerating:") + "#{args.size} files at #{t} "
|
||||
n = modified.length + added.length + removed.length
|
||||
print Jekyll.logger.formatted_topic("Regenerating:") + "#{n} files at #{t} "
|
||||
self.process_site(site)
|
||||
puts "...done."
|
||||
end
|
||||
|
||||
dw.start
|
||||
|
||||
unless options['serving']
|
||||
trap("INT") do
|
||||
puts " Halting auto-regeneration."
|
||||
|
|
Loading…
Reference in New Issue