diff --git a/lib/dataloaderb/conf_creator.rb b/lib/dataloaderb/conf_creator.rb index 43ab207..eae6a61 100644 --- a/lib/dataloaderb/conf_creator.rb +++ b/lib/dataloaderb/conf_creator.rb @@ -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 diff --git a/lib/dataloaderb/process_runner.rb b/lib/dataloaderb/process_runner.rb index ac73f5a..d83762e 100644 --- a/lib/dataloaderb/process_runner.rb +++ b/lib/dataloaderb/process_runner.rb @@ -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 @@ -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 diff --git a/spec/dataloaderb/process_runner_spec.rb b/spec/dataloaderb/process_runner_spec.rb index 8744106..1ef8da3 100644 --- a/spec/dataloaderb/process_runner_spec.rb +++ b/spec/dataloaderb/process_runner_spec.rb @@ -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 @@ -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")