class Dataloaderb::ProcessRunner

Public Class Methods

new(bin_path, opts = {}) { |self| ... } click to toggle source

Create the process runner and specify the path to the Apex Data Loader executable (batch) files.

# File lib/dataloaderb/process_runner.rb, line 7
def initialize(bin_path, opts = {}, &block)
  @bin_path  = bin_path
  @conf_path = nil
  @opts      = opts
  yield self if block_given?
end

Public Instance Methods

execute_process(process_name) click to toggle source
# File lib/dataloaderb/process_runner.rb, line 36
def execute_process(process_name)
  # @bin_path and @conf_path are full paths at this point
  `#{get_process_execute_command @bin_path, @conf_path, process_name}`
end
get_process_bat_path(bin_path) click to toggle source

Given the path to the Apex Data Loader bin directory, return the expanded path of the process.bat file to be executed.

# File lib/dataloaderb/process_runner.rb, line 52
def get_process_bat_path(bin_path)
  File.expand_path "#{bin_path}/process.bat"
end
get_process_execute_command(bin_path, conf_path, process_name) click to toggle source

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 command that the operating system needs to run to execute the process.

# File lib/dataloaderb/process_runner.rb, line 46
def get_process_execute_command(bin_path, conf_path, process_name)
  "#{get_process_bat_path(bin_path)} #{conf_path} #{process_name}"
end
run(*yamls) click to toggle source

Run one or more processes. Specify the processes to run by passing one or more paths to process Yaml definitions.

# File lib/dataloaderb/process_runner.rb, line 16
def run(*yamls)
  if yamls.empty? || yamls.flatten.empty?
    raise ArgumentError, "You must pass at least one argument to Dataloaderb::ProcessRunner#run"
  end

  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

Protected Instance Methods

create_configuration(xml) click to toggle source
# File lib/dataloaderb/process_runner.rb, line 58
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
remove_configuration() click to toggle source
# File lib/dataloaderb/process_runner.rb, line 67
def remove_configuration
  FileUtils.remove_entry_secure(@conf_path) unless @conf_path.nil?
end