class Qwik::Farm
Bundle many sites to one object.
Public Class Methods
new(config, memory)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 17 def initialize(config, memory) @config = config @memory = memory @logger = @memory[:logger] @data_path = @config.sites_dir.path @grave_path = @config.grave_dir.path @top_sitename = @config.default_sitename if $update_group_files $update_group_files = false # Set before to do it. update_group_files end end
Public Instance Methods
check_inactive_sites()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 97 def check_inactive_sites inactive_sites = [] list().each {|sitename| # Do not bury default site. next if sitename == @top_sitename site = get_site(sitename) # Check a particular page to check the directory is a site or not. next if ! site.exist?('_SiteConfig') inactive_sites << sitename if site && site.inactive? } return inactive_sites end
close_all()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 59 def close_all list().each {|sitename| site = self.get_site(sitename) site.close if site } end
get_site(sitename)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 37 def get_site(sitename) sitepath = @data_path + sitename # FIXME: Should we check the directory everytime? if ! sitepath.directory? # At the first, check the directory. return nil # No such site. end # Now, I am sure that we have the directory for the site. # Create a new site object and return it. return Site.new(@config, @memory, sitename) end
Also aliased as: exist?
get_top_site()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 51 def get_top_site return get_site(@top_sitename) end
list()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 55 def list return check_all_sites.sort end
make_site(sitename, now = Time.now)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 66 def make_site(sitename, now = Time.now) sitepath = @data_path + sitename raise 'site already exist' if sitepath.exist? # Check the path first. sitepath.mkdir page = (sitepath + "_QwikSite.txt") page.write(now.rfc_date) return nil end
sweep()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 75 def sweep @logger.log(WEBrick::Log::INFO, 'start sweep') unless $test log = @memory[:bury_log] unless $test log.info("start sweep") end inactive_sites = check_inactive_sites buried = [] inactive_sites.each {|sitename| @logger.log(WEBrick::Log::INFO, 'sweep '+sitename) unless $test buried << bury(sitename) } unless $test log.info("end sweep") end return buried end
update_group_files()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 30 def update_group_files list().each {|sitename| site = get_site(sitename) site.member.update_group_files } end
Private Instance Methods
bury(sitename)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 129 def bury(sitename) site = get_site(sitename) if site.unconfirmed? dump_site(site, 'deleted') delete(site) return end dump_site(site, 'buried') sitepath = site.path dirtime = sitepath.mtime.to_i @grave_path.check_directory (sitepath.parent + ".grave").check_directory while true tempgravepath = sitepath.parent + ".grave" + "#{dirtime}_#{sitename}" gravesitepath = @grave_path + "#{dirtime}_#{sitename}" unless tempgravepath.exist? || gravesitepath.exist? # step1. move atomically on same disk volume sitepath.rename(tempgravepath) # step2. move across disk volume #FileUtils.mv(tempgravepath, gravesitepath) break end dirtime += 1 end #return gravesitepath return tempgravepath end
bury_dummy(sitename)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 158 def bury_dummy(sitename) site = get_site(sitename) dump_site(site, 'bury dummy') return site.path end
check_all_sites()
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 112 def check_all_sites sites = Array.new # Check the direcotry entries. @data_path.each_entry {|entry| pa = @data_path + entry next if ! pa.directory? # is not a directory? sitename = entry.to_s next if sitename[0] == ?. # begin with dot? next if sitename == 'CVS' #next if (pa + '_SiteConfig.txt').exist? # check the site. sites << sitename } return sites end
delete(site)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 185 def delete(site) sitepath = site.path sitepath.remove_directory end
dump_site(site, message)
click to toggle source
# File vendor/qwik/lib/qwik/farm.rb, line 165 def dump_site(site, message) log = @memory[:bury_log] buff = StringIO.new buff.puts("#{message}: #{site.sitename}") ml_life_time = site.siteconfig['ml_life_time'].to_i days = ml_life_time / (60*60*24) buff.puts("ml_life_time: #{ml_life_time} (#{days}d)") site.path.children.sort{|a,b| b.mtime <=> a.mtime }.each do |path| buff << path.mtime.strftime("%Y-%m-%d %H:%M:%S ") buff << sprintf("% 8d ", path.size) buff << path.basename.to_s buff << "\n" end unless $test log.info(buff.string) end end