Permalink
Browse files

updated tracking for wu-sync commands so that each file can be watched

  • Loading branch information...
1 parent 9a2bca7 commit c73d5cf8c94c75063fd1c854ee1d67cb24c416ee @dhruvbansal dhruvbansal committed Dec 12, 2013
View
13 lib/wukong-load/syncers/ftp_syncer.rb
@@ -8,6 +8,9 @@ module Load
# do the heavy-lifting.
class FTPSyncer < Syncer
+ # A list of files that was transferred, each in full or in part.
+ attr_accessor :files
+
include Logging
# A mapping between protocal names and the standard ports
@@ -84,6 +87,11 @@ def validate
true
end
+ # :nodoc:
+ def setup
+ self.files = []
+ end
+
# Logs what's about to happen.
def before_sync
super()
@@ -176,7 +184,10 @@ def lftp_program
# :nodoc:
def handle_output line
- log.debug(line.chomp)
+ content = line.chomp
+ log.debug(content)
+ (self.files << $1 if content =~ /^Transferring file `(.+)'/)
+ rescue
end
end
View
26 lib/wukong-load/syncers/prepare_syncer.rb
@@ -159,21 +159,25 @@ def validate
# static files.
attr_accessor :handler
- # Tracks counts of files that were processed.
+ # A list of files that was processed during this invocation.
attr_accessor :files
+ # Tracks counts of files examined, new, ignored, in error, and
+ # processed.
+ attr_accessor :counts
+
# Did all input files process?
#
# @return [true, false]
def success?
- self.files[:examined] == 0 || self.files[:error] == 0
+ self.counts[:examined] == 0 || self.counts[:error] == 0
end
# Did any of the input files fail to process?
#
# @return [true, false]
def failed?
- self.files[:error] > 0
+ self.counts[:error] > 0
end
# The absolute path to the input directory.
@@ -198,7 +202,8 @@ def setup
super()
load_file_state
create_handler
- self.files = { examined: 0, new: 0, processed: 0, ignored: 0, error: 0 }
+ self.files = []
+ self.counts = { examined: 0, new: 0, processed: 0, ignored: 0, error: 0 }
end
# Logs a message.
@@ -210,7 +215,7 @@ def before_sync
# Logs a message.
def after_sync
super()
- log.debug("#{settings[:input]}: #{self.files[:examined]} files, #{self.files[:new]} new, #{self.files[:processed]} processed, #{self.files[:ignored]} ignored, #{self.files[:error]} error")
+ log.debug("#{settings[:input]}: #{self.counts[:examined]} files, #{self.counts[:new]} new, #{self.counts[:processed]} processed, #{self.counts[:ignored]} ignored, #{self.counts[:error]} error")
end
# Perform the sync.
@@ -223,9 +228,9 @@ def sync
started_at = Time.now
absolute_input_directory.find do |path|
next if path.directory?
- self.files[:examined] += 1
+ self.counts[:examined] += 1
if already_processed?(path)
- self.files[:ignored] += 1
+ self.counts[:ignored] += 1
next
end
same_size?(path) ? process!(path) : remember_size!(path)
@@ -261,10 +266,11 @@ def same_size?(path)
# @see Handler#process
def process! path
if handler.process(path)
- self.files[:processed] += 1
+ self.counts[:processed] += 1
+ self.files << handler.fragment_for(path)
file_state[path.to_s] = true
else
- self.files[:error] += 1
+ self.counts[:error] += 1
end
end
@@ -273,7 +279,7 @@ def process! path
#
# @param [Pathname] path
def remember_size!(path)
- self.files[:new] += 1
+ self.counts[:new] += 1
file_state[path.to_s] = path.size
end
View
9 lib/wukong-load/syncers/prepare_syncer/handler.rb
@@ -127,6 +127,15 @@ def relative_path_of file, dir
file.relative_path_from(dir)
end
+ # Return the path relative to the `input` directory of the
+ # `original` path.
+ #
+ # @param [Pathname] original
+ # @return [Pathname]
+ def fragment_for original
+ relative_path_of(original, settings[:input])
+ end
+
# Returns the top-level directory of the `file`, relative to
# `dir`.
#

0 comments on commit c73d5cf

Please sign in to comment.