Module: Condor

Defined in:
lib/condor.rb

Overview

Wrapper for the Condor distributed computing system.

Defined Under Namespace

Classes: ExecutableException, ExecutePermissionException, NoExecutableException, SubmitFile

Constant Summary collapse

VERSION =
"2.0.0"
LOGGER =

Logger used by all objects in this module. This is initialized at module load time. The default log level is ERROR.

initialize_logger

Class Method Summary collapse

Class Method Details

.set_log_level(level) ⇒ Object

Set the logging level. For example:

> Condor.set_log_level(Logger::DEBUG)


45
46
47
# File 'lib/condor.rb', line 45

def Condor.set_log_level(level)
  Condor::LOGGER.level = level
end

.submit(executable, command_line_arguments, options = {}) ⇒ Object

This function runs the specified executable and arguments as a Condor job. It creates a condor_submit.nnn file in the current directory.



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/condor.rb', line 129

def Condor.submit(executable, command_line_arguments, options = {})
  if executable.nil? or executable.empty?
    raise "You must specify a command to run"
  end
  # Condor needs a full path to a executable program.  Raise an error if
  # this cannot be determined.
  executable.strip!
  full_exec_paths = File.files_on_path(executable)
  raise NoExecutableException.new(executable) if full_exec_paths.empty?
  executables = full_exec_paths.select{|f| File.executable?(f)}
  if executables.empty?
    raise ExecutePermissionException.new(full_exec_paths.join(","))
  end
  executable = executables.first
  # Create a unique submit file name of the form condor_submit.nnn.
  n = 0
  while n < 1000
    ext = sprintf("%03d", n)
    submit_name = "condor_submit.#{ext}"
    break if not File.exists?(submit_name)
    n += 1
  end
  raise "Cannot create unique submit file name" if n == 1000
  # Optionally read arguments from a file.
  arguments_list = if options.has_key?(:argfile)
    open(options[:argfile]) do |file|
      file.collect do |line|
        line.strip!
        next if line.empty?
        command_line_arguments + line.split
      end
    end
  else
    [command_line_arguments]
  end
  # Optionally read configuration from a file.
  config = if options.has_key?(:configfile)
    open(options[:configfile]) {|f| YAML.load(f)}
  else
    {}
  end
  # Write Condor information to the submit file.
  File.open(submit_name, "w") do |file|
    file << Condor::SubmitFile.new(executable, arguments_list, config,
                                   options[:output], options[:error])
  end
  # Optionally submit the Condor job.
  `condor_submit #{submit_name}` if options[:submit]
end