Skip to content

Commit

Permalink
Use process_watcher gem instead of private copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
Graham Hughes committed Nov 8, 2010
1 parent 1ca37d3 commit 781a52a
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 756 deletions.
1 change: 1 addition & 0 deletions Rakefile
Expand Up @@ -42,6 +42,7 @@ task :gem => 'pkg' do
end

CLEAN.include('pkg')
CLEAN.include('right_scraper_all/lib')

# == Unit Tests == #

Expand Down
98 changes: 0 additions & 98 deletions right_scraper/lib/right_scraper/win32/process_monitor.rb

This file was deleted.

81 changes: 0 additions & 81 deletions right_scraper/spec/watcher_spec.rb

This file was deleted.

2 changes: 0 additions & 2 deletions right_scraper_base/lib/right_scraper_base.rb
Expand Up @@ -29,8 +29,6 @@
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'builders', 'union'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'cookbook'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'logger'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'processes', 'watcher'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'process_watcher'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'repository'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'repositories', 'download'))
require File.expand_path(File.join(File.dirname(__FILE__), 'right_scraper_base', 'scanners', 'base'))
Expand Down
11 changes: 7 additions & 4 deletions right_scraper_base/lib/right_scraper_base/builders/archive.rb
Expand Up @@ -22,15 +22,13 @@
#++

require File.expand_path(File.join(File.dirname(__FILE__), 'base'))
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'process_watcher'))
require 'process_watcher'
require 'digest/sha1'

module RightScale
module Builders
# Class for building tarballs from filesystem based checkouts.
class Archive < Builder
include ProcessWatcher

# Create a new ArchiveBuilder. In addition to the options
# recognized by Builder, recognizes :scraper,
# :max_bytes, and :max_seconds.
Expand All @@ -55,8 +53,13 @@ def go(dir, cookbook)
@logger.operation(:creating_archive) do
exclude_declarations =
@scraper.ignorable_paths.map {|path| ["--exclude", path]}
# because this writes to stdout, it should be impossible for
# it to violate space requirements.
cookbook.data[:archive] =
watch("tar", ["-C", dir, "-c", exclude_declarations, "."].flatten, @max_bytes, @max_seconds)
ProcessWatcher.watch("tar", ["-C", dir, "-c", exclude_declarations, "."].flatten, nil,
-1, @max_seconds) do |phase, command, exception|
@logger.note_phase(phase, :running_command, command, exception)
end
end
end
end
Expand Down
27 changes: 23 additions & 4 deletions right_scraper_base/lib/right_scraper_base/logger.rb
Expand Up @@ -48,15 +48,34 @@ def initialize(*args)
# type(Symbol):: operation type identifier
# explanation(String):: optional explanation
def operation(type, explanation="")
@exceptional = false
begin
yield
note_phase(:begin, type, explanation)
result = yield
note_phase(:commit, type, explanation)
result
rescue
note_phase(:abort, type, explanation, $!)
raise
end
end

# Note an event to the log. In this base class this calls
# note_error when an error occurs, but subclasses will presumably
# want to override it.
#
# === Parameters
# phase(Symbol):: phase of operation; one of :begin, :commit, :abort
# type(Symbol):: operation type identifier
# explanation(String):: explanation of operation
# exception(Exception):: optional exception (only if +phase+ is :abort)
def note_phase(phase, type, explanation, exception=nil)
case phase
when :begin then @exceptional = false
when :abort then
unless @exceptional
note_error($!, type, explanation)
note_error(exception, type, explanation)
@exceptional = true
end
raise
end
end

Expand Down
26 changes: 12 additions & 14 deletions right_scraper_base/lib/right_scraper_base/loggers/noisy.rb
Expand Up @@ -32,25 +32,23 @@ def initialize(*args)
super
@pending = []
end
# Begin an operation that merits logging. Will write the
# details to the log, including a visual indicator of how many
# nested operations are currently pending.

# Note an event to the log, including a visual indicator of how
# many nested operations are currently pending.
#
# === Parameters
# phase(Symbol):: phase of operation; one of :begin, :commit, :abort
# type(Symbol):: operation type identifier
# explanation(String):: optional explanation
def operation(type, explanation="")
begin
# explanation(String):: explanation of operation
# exception(Exception):: optional exception (only if +phase+ is :abort)
def note_phase(phase, type, explanation, exception=nil)
if phase == :begin
@pending.push [type, explanation]
debug("#{depth_str} begin #{immediate_context}")
result = super
debug("#{depth_str} close #{immediate_context}")
@pending.pop
return result
rescue
debug("#{depth_str} abort #{immediate_context}")
end
super
debug("#{depth_str} #{phase} #{immediate_context}")
unless phase == :begin
@pending.pop
raise
end
end

Expand Down
89 changes: 0 additions & 89 deletions right_scraper_base/lib/right_scraper_base/process_watcher.rb

This file was deleted.

0 comments on commit 781a52a

Please sign in to comment.