Skip to content

Commit

Permalink
ProcessRunner creates XML file and runs processes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Tilley committed Jan 7, 2011
1 parent 2e1592b commit 493aa65
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
10 changes: 0 additions & 10 deletions lib/dataloaderb/conf_creator.rb
Expand Up @@ -40,15 +40,5 @@ def to_xml
def get_binding
binding
end

# def write_xml(xml)
# base_tmpdir = @options[:tmp_dir] || Dir.tmpdir
# dir = Dir.mktmpdir(['', Dataloaderb::Support.unique_id], base_tmpdir)
# begin
# ##
# ensure
# FileUtils.remove_entry_secure dir
# end
# end
end
end
34 changes: 30 additions & 4 deletions lib/dataloaderb/process_runner.rb
Expand Up @@ -5,8 +5,9 @@ class ProcessRunner
# Create the process runner and specify the path to
# the Apex Data Loader executable (batch) files.
def initialize(bin_path, opts = {})
@bin_path = bin_path
@opts = opts
@bin_path = bin_path
@conf_path = nil
@opts = opts
end

# Run one or more processes. Specify the processes to run by passing
Expand All @@ -16,16 +17,41 @@ def run(*yamls)
raise ArgumentError, "You must pass at least one argument to Dataloaderb::ProcessRunner#run"
end

creator = Dataloaderb::ConfCreator.new(yamls, opts)
creator = Dataloaderb::ConfCreator.new(yamls, @opts)
# We now have a Hash of ProcessDefinitions in creator#processes.
# We can also access the full XML for the entire set of processes via
# creator#to_xml.
# We can access a specific process via creator#processes['processName'].
begin
create_configuration(creator.to_xml)
creator.processes.each do |name, definition|
execute_process(name)
end
ensure
remove_configuration
end
end

def execute_process(process_name)
# @bin_path and @conf_path are full paths at this point
`#{get_process_execute_command}`
`#{get_process_execute_command @bin_path, @conf_path, process_name}`
end

protected

def create_configuration(xml)
base_tmpdir = @opts[:tmp_dir] || Dir.tmpdir
@conf_path = Dir.mktmpdir(['', Dataloaderb::Support.unique_id], base_tmpdir)
conf_file_path = "#{File.expand_path(@conf_path)}/process-conf.xml"
File.open(conf_file_path, "w+") do |file|
file.write(xml)
end
end

def remove_configuration
FileUtils.remove_entry_secure(@conf_path) unless @conf_path.nil?
end

# Given the path to the Apex Data Loader bin directory, the
# path to the folder with the process-conf.xml file, and the
# name of a process defined in the XML to run, return the
Expand Down
12 changes: 11 additions & 1 deletion spec/dataloaderb/process_runner_spec.rb
Expand Up @@ -3,7 +3,7 @@

describe Dataloaderb::ProcessRunner do
before :each do
@runner = Dataloaderb::ProcessRunner.new('spec/fixtures/bin')
@runner = Dataloaderb::ProcessRunner.new('spec/fixtures/bin')
end

describe "#get_process_bat_path" do
Expand All @@ -28,6 +28,16 @@
end
end

describe "#create_configuration" do
it "should create a new directory under the temporary directory" do
@runner.instance_variable_set(:@opts, { :tmp_dir => './tmp/' })
@runner.send(:create_configuration, 'fake xml data')
tmp_dir = @runner.instance_variable_get(:@conf_path)
IO.readlines("#{tmp_dir}/process-conf.xml")[0].should == "fake xml data"
FileUtils.remove_entry_secure(tmp_dir)
end
end

describe "#get_process_execute_command" do
it "should return the correct execution command" do
path = @runner.send(:get_process_execute_command, "sf/bin", "myconf", "someUpserts")
Expand Down

0 comments on commit 493aa65

Please sign in to comment.