Class: Origen::Application::LSFManager
- Includes:
- Callbacks
- Defined in:
- lib/origen/application/lsf_manager.rb
Overview
This class is responsible for co-ordinating and monitoring all submissions to the LSF. This is in contrast to Origen::Application::LSF which is an API for talking to the LSF.
Instance Attribute Summary collapse
-
#current_command ⇒ Object
This will be set by the command dispatcher to reflect the currently executing command.
Instance Method Summary collapse
- #add_command_option(*opts) ⇒ Object
-
#build_log(_options = {}) ⇒ Object
Build the log file from the completed jobs.
- #classify_jobs ⇒ Object
-
#clear(options) ⇒ Object
Clear jobs from memory.
- #clear_all ⇒ Object
- #clear_caches ⇒ Object
- #command_options(command_str) ⇒ Object
-
#command_options=(opts) ⇒ Object
This will be called by the command dispatcher to record any options that were passed in when launching the current command.
- #command_prefix(id, dependents) ⇒ Object
- #completed_jobs ⇒ Object
- #execute_remotely(options = {}) ⇒ Object
- #extract_ids(jobs_or_ids) ⇒ Object
- #failed_file(id) ⇒ Object
-
#failed_jobs ⇒ Object
Failed jobs are those that started to produce a log file but did not complete.
- #generate_job_id ⇒ Object
-
#initialize ⇒ LSFManager
constructor
A new instance of LSFManager.
-
#job_completed?(id) ⇒ Boolean
Returns trus if the given job ID generated a complete file when run on the LSF.
-
#job_failed(id) ⇒ Object
Register that the given job ID has failed on the LSF.
- #job_failed?(id) ⇒ Boolean
-
#job_passed(id) ⇒ Object
Register that the given job ID has completed successfully on the LSF.
- #job_passed?(id) ⇒ Boolean
- #job_running?(id) ⇒ Boolean
- #job_started(id) ⇒ Object
- #job_started?(id) ⇒ Boolean
-
#log_file(id) ⇒ Object
Returns the logfile that should be used by a given process on the LSF, this should be be guaranteed to be unique.
- #log_file_directory ⇒ Object
- #log_file_name(id) ⇒ Object
-
#lost_jobs ⇒ Object
Lost jobs are ones that for whatever reason did not start, or at least get far enough to log that they started.
- #on_origen_shutdown(_options = {}) ⇒ Object
- #outstanding_jobs? ⇒ Boolean
- #passed_file(id) ⇒ Object
- #passed_jobs ⇒ Object
- #print_details(options = {}) ⇒ Object
- #print_details_of(job) ⇒ Object
- #print_status(options = {}) ⇒ Object
- #queuing_jobs ⇒ Object
- #remote_jobs ⇒ Object
- #remote_jobs_file ⇒ Object
- #restore_remote_jobs ⇒ Object
-
#resubmit(options) ⇒ Object
Resubmit jobs.
- #resubmit_job(job) ⇒ Object
- #running_jobs ⇒ Object
- #save_remote_jobs ⇒ Object
- #started_file(id) ⇒ Object
- #stats ⇒ Object
- #submit_job(command, options = {}) ⇒ Object
- #submit_origen_job(cmd, options = {}) ⇒ Object
- #time_ago(time) ⇒ Object
-
#wait_for_completion(options = {}) ⇒ Object
Waits for all jobs to complete, will retry lost jobs (optionally failed jobs).
Methods included from Callbacks
Constructor Details
#initialize ⇒ LSFManager
Returns a new instance of LSFManager.
14 15 |
# File 'lib/origen/application/lsf_manager.rb', line 14 def initialize end |
Instance Attribute Details
#current_command ⇒ Object
This will be set by the command dispatcher to reflect the currently executing command. If LSF jobs are spawned with the same command then any options passed to the parent command will automatically be forwarded to the children.
12 13 14 |
# File 'lib/origen/application/lsf_manager.rb', line 12 def current_command @current_command end |
Instance Method Details
#add_command_option(*opts) ⇒ Object
470 471 472 473 |
# File 'lib/origen/application/lsf_manager.rb', line 470 def add_command_option(*opts) @command_options ||= [] @command_options += opts end |
#build_log(_options = {}) ⇒ Object
Build the log file from the completed jobs
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/origen/application/lsf_manager.rb', line 243 def build_log( = {}) Origen.log.info '*' * 70 completed_jobs.each do |job| File.open(log_file(job[:id])) do |f| last_line_blank = false f.readlines.each do |line| # Capture and combine the per job stats that look like this: # Total patterns: 1 1347 0.003674 # New patterns: 0 # Changed patterns: 1 # FAILED patterns: 1 # Total files: 1 # New files: 0 # Changed files: 0 # FAILED files: 1 begin line.gsub!(/\e\[\d+m/, '') # Remove any coloring if line =~ /Total patterns:\s+(\d+)/ stats.completed_patterns += Regexp.last_match[1].to_i elsif line =~ /Total vectors:\s+(\d+)/ stats.total_vectors += Regexp.last_match[1].to_i elsif line =~ /Total duration:\s+(\d+\.\d+)/ stats.total_duration += Regexp.last_match[1].to_f elsif line =~ /Total files:\s+(\d+)/ stats.completed_files += Regexp.last_match[1].to_i elsif line =~ /Changed patterns:\s+(\d+)/ stats.changed_patterns += Regexp.last_match[1].to_i elsif line =~ /Changed files:\s+(\d+)/ stats.changed_files += Regexp.last_match[1].to_i elsif line =~ /New patterns:\s+(\d+)/ stats.new_patterns += Regexp.last_match[1].to_i elsif line =~ /New files:\s+(\d+)/ stats.new_files += Regexp.last_match[1].to_i elsif line =~ /FAILED patterns:\s+(\d+)/ stats.failed_patterns += Regexp.last_match[1].to_i elsif line =~ /FAILED files:\s+(\d+)/ stats.failed_files += Regexp.last_match[1].to_i elsif line =~ /ERROR!/ stats.errors += 1 Origen.log.send :relog, line else # Compress multiple blank lines if line =~ /^\s*$/ || line =~ /.*\|\|\s*$/ unless last_line_blank Origen.log.info last_line_blank = true end else # Screen std origen output unless line =~ / origen save/ || line =~ /Insecure world writable dir/ || line =~ /To save all of/ line.strip! # line.sub!(/.*\|\| /, '') Origen.log.send :relog, line last_line_blank = false end end end rescue # Sometimes illegal UTF-8 characters can get into crash dumps, if this # happens just print the line out rather than die Origen.log.error line end end end end Origen.log.info '*' * 70 stats.print_summary end |
#classify_jobs ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 |
# File 'lib/origen/application/lsf_manager.rb', line 479 def classify_jobs clear_caches queuing_job_ids = Origen.app.lsf.queuing_job_ids running_job_ids = Origen.app.lsf.running_job_ids remote_jobs.each do |_id, job| # If the status has already been determined send it straight to the bucket if job[:status] send("#{job[:status]}_jobs") << job else if job[:lsf_id] == :error job[:status] = :lost lost_jobs << job elsif job_completed?(job[:id]) if job_passed?(job[:id]) job[:status] = :passed passed_jobs << job elsif job_failed?(job[:id]) job[:status] = :failed failed_jobs << job end else if running_job_ids.include?(job[:lsf_id]) running_jobs << job # Once we have assigned a job as running make sure the job is marked as started # It can flicker back to queued if the started file takes a long time to arrive # from the remote host job_started(job[:lsf_id]) elsif queuing_job_ids.include?(job[:lsf_id]) queuing_jobs << job elsif job_started?(job[:id]) # There can be considerable latency between the job writing the passed/failed # file remotely and it showing up on the local machine. # Give some buffer to that before declaring the file lost. if job[:completed_at] if (Time.now - job[:completed_at]) < 60 running_jobs << job else lost_jobs << job end else job[:completed_at] = Time.now running_jobs << job end # Give jobs submitted less than a minute ago the benefit of the # doubt, they may not have shown up in bjobs yet elsif (Time.now - job[:submitted_at]) < 60 queuing_jobs << job else lost_jobs << job end end end end end |
#clear(options) ⇒ Object
Clear jobs from memory
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/origen/application/lsf_manager.rb', line 195 def clear() if [:type] if [:type] == :all File.delete(remote_jobs_file) if File.exist?(remote_jobs_file) @remote_jobs = {} return else send("#{[:type]}_jobs").each do |job| remote_jobs.delete(job[:id]) end end else remote_jobs.delete([:id]) end end |
#clear_all ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/origen/application/lsf_manager.rb', line 211 def clear_all File.delete(remote_jobs_file) if File.exist?(remote_jobs_file) if File.exist?(log_file_directory) FileUtils.rm_rf(log_file_directory) end FileUtils.mkdir_p(log_file_directory) @remote_jobs = {} clear_caches end |
#clear_caches ⇒ Object
534 535 536 537 538 539 540 |
# File 'lib/origen/application/lsf_manager.rb', line 534 def clear_caches @running_jobs = nil @queuing_jobs = nil @passed_jobs = nil @failed_jobs = nil @lost_jobs = nil end |
#command_options(command_str) ⇒ Object
425 426 427 428 429 430 431 432 433 434 |
# File 'lib/origen/application/lsf_manager.rb', line 425 def (command_str) command_str.sub(/origen\s*/, '') =~ /(\w+)/ command = Regexp.last_match[1] command = ORIGEN_COMMAND_ALIASES[command] || command if command == current_command @command_options else '' end end |
#command_options=(opts) ⇒ Object
This will be called by the command dispatcher to record any options that were passed in when launching the current command. These will be automatically appended if the current command spawns any LSF jobs that will invoke the same command.
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/origen/application/lsf_manager.rb', line 440 def (opts) # Ensure these options are removed, these are either incompatible with the LSF, # or will already have been added elsewhere { ['-h', '--help'] => false, ['-w', '--wait'] => false, ['-d', '--debug'] => false, ['-c', '--continue'] => false, '--exec_remote' => false, ['-t', '--target'] => '*', ['-e', '--environment'] => '*', '--id' => '*', ['-l', '--lsf'] => %w(add clear) }.each do |names, values| [names].flatten.each do |name| ix = opts.index(name) if ix opts.delete_at(ix) [values].flatten.each do |value| if value && (value == '*' || opts[ix] == value) opts.delete_at(ix) end end end end end @command_options ||= [] @command_options += opts end |
#command_prefix(id, dependents) ⇒ Object
410 411 412 413 414 415 416 417 418 419 420 421 422 423 |
# File 'lib/origen/application/lsf_manager.rb', line 410 def command_prefix(id, dependents) origen = `which origen` # http://rubular.com/r/wgKi73KjUo if origen =~ /(^\/run\/pkg\/fs-origen-\/[^\/]+)/ prefix = "source #{Regexp.last_match[1]}/origen_setup; " else prefix = "cd #{Origen.top}; source source_setup; " end prefix += "cd #{Origen.root}; origen l --execute --id #{id} " unless dependents.empty? prefix += "--dependents #{dependents.join(',')} " end prefix end |
#completed_jobs ⇒ Object
550 551 552 |
# File 'lib/origen/application/lsf_manager.rb', line 550 def completed_jobs passed_jobs + failed_jobs end |
#execute_remotely(options = {}) ⇒ Object
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/origen/application/lsf_manager.rb', line 619 def execute_remotely( = {}) job_started([:id]) begin if [:dependents] wait_for_completion(ids: [:dependents], poll_duration_in_seconds: 1, # Don't wait long by the time this runs the LSF # should have guaranteed the job has run timeout_in_seconds: 120 ) unless [:dependents].all? { |id| job_passed?(id) } File.open(log_file([:id]), 'w') do |f| f.puts "*** ERROR! *** #{[:cmd].join(' ')} ***" f.puts 'Dependents failed!' end fail 'Dependents failed!' end end if [:cmd].is_a?(Array) cmd = [:cmd].join(' ') else cmd = [:cmd] end output = `#{cmd} 2>&1` File.open(log_file([:id]), 'w') do |f| f.write output end if $CHILD_STATUS.success? job_passed([:id]) else job_failed([:id]) end rescue job_failed([:id]) end end |
#extract_ids(jobs_or_ids) ⇒ Object
388 389 390 |
# File 'lib/origen/application/lsf_manager.rb', line 388 def extract_ids(jobs_or_ids) jobs_or_ids.map { |j| j.is_a?(Hash) ? j[:id] : j } end |
#failed_file(id) ⇒ Object
328 329 330 |
# File 'lib/origen/application/lsf_manager.rb', line 328 def failed_file(id) "#{log_file_directory}/#{log_file_name(id)}.failed" end |
#failed_jobs ⇒ Object
Failed jobs are those that started to produce a log file but did not complete
559 560 561 |
# File 'lib/origen/application/lsf_manager.rb', line 559 def failed_jobs @failed_jobs ||= [] end |
#generate_job_id ⇒ Object
593 594 595 |
# File 'lib/origen/application/lsf_manager.rb', line 593 def generate_job_id "#{Time.now.to_f}".gsub('.', '') end |
#job_completed?(id) ⇒ Boolean
Returns trus if the given job ID generated a complete file when run on the LSF. The complete file is created at the end of a job run and its presence indicates that the job ran and got past the generation/compile stage without crashing.
572 573 574 575 |
# File 'lib/origen/application/lsf_manager.rb', line 572 def job_completed?(id) job_started?(id) && (job_passed?(id) || job_failed?(id)) end |
#job_failed(id) ⇒ Object
Register that the given job ID has failed on the LSF
347 348 349 |
# File 'lib/origen/application/lsf_manager.rb', line 347 def job_failed(id) `touch #{failed_file(id)}` end |
#job_failed?(id) ⇒ Boolean
589 590 591 |
# File 'lib/origen/application/lsf_manager.rb', line 589 def job_failed?(id) File.exist?(failed_file(id)) end |
#job_passed(id) ⇒ Object
Register that the given job ID has completed successfully on the LSF
342 343 344 |
# File 'lib/origen/application/lsf_manager.rb', line 342 def job_passed(id) `touch #{passed_file(id)}` end |
#job_passed?(id) ⇒ Boolean
585 586 587 |
# File 'lib/origen/application/lsf_manager.rb', line 585 def job_passed?(id) File.exist?(passed_file(id)) end |
#job_running?(id) ⇒ Boolean
577 578 579 |
# File 'lib/origen/application/lsf_manager.rb', line 577 def job_running?(id) !job_completed?(id) end |
#job_started(id) ⇒ Object
351 352 353 |
# File 'lib/origen/application/lsf_manager.rb', line 351 def job_started(id) `touch #{started_file(id)}` end |
#job_started?(id) ⇒ Boolean
581 582 583 |
# File 'lib/origen/application/lsf_manager.rb', line 581 def job_started?(id) File.exist?(started_file(id)) end |
#log_file(id) ⇒ Object
Returns the logfile that should be used by a given process on the LSF, this should be be guaranteed to be unique
316 317 318 |
# File 'lib/origen/application/lsf_manager.rb', line 316 def log_file(id) "#{log_file_directory}/#{log_file_name(id)}" end |
#log_file_directory ⇒ Object
337 338 339 |
# File 'lib/origen/application/lsf_manager.rb', line 337 def log_file_directory "#{Origen.root}/.lsf/remote_logs" end |
#log_file_name(id) ⇒ Object
332 333 334 335 |
# File 'lib/origen/application/lsf_manager.rb', line 332 def log_file_name(id) # host = `hostname`.strip "#{id}.txt" end |
#lost_jobs ⇒ Object
Lost jobs are ones that for whatever reason did not start, or at least get far enough to log that they started
565 566 567 |
# File 'lib/origen/application/lsf_manager.rb', line 565 def lost_jobs @lost_jobs ||= [] end |
#on_origen_shutdown(_options = {}) ⇒ Object
609 610 611 |
# File 'lib/origen/application/lsf_manager.rb', line 609 def on_origen_shutdown( = {}) save_remote_jobs if @remote_jobs end |
#outstanding_jobs? ⇒ Boolean
190 191 192 |
# File 'lib/origen/application/lsf_manager.rb', line 190 def outstanding_jobs? (running_jobs + queuing_jobs).size > 0 end |
#passed_file(id) ⇒ Object
320 321 322 |
# File 'lib/origen/application/lsf_manager.rb', line 320 def passed_file(id) "#{log_file_directory}/#{log_file_name(id)}.passed" end |
#passed_jobs ⇒ Object
554 555 556 |
# File 'lib/origen/application/lsf_manager.rb', line 554 def passed_jobs @passed_jobs ||= [] end |
#print_details(options = {}) ⇒ Object
125 126 127 128 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 |
# File 'lib/origen/application/lsf_manager.rb', line 125 def print_details( = {}) if [:id] Origen.log.info "Job: #{[:id]}" Origen.log.info '----' + '-' * [:id].length print_details_of(remote_jobs[[:id]]) else [:type] ||= :all if [:type] == :all || [:type] == :queuing Origen.log.info '' Origen.log.info 'Queuing' Origen.log.info '-------' queuing_jobs.each { |j| print_details_of(j) } end if [:type] == :all || [:type] == :running Origen.log.info '' Origen.log.info 'Running' Origen.log.info '-------' running_jobs.each { |j| print_details_of(j) } end if [:type] == :all || [:type] == :lost Origen.log.info '' Origen.log.info 'Lost' Origen.log.info '----' lost_jobs.each { |j| print_details_of(j) } end if [:type] == :all || [:type] == :passed Origen.log.info '' Origen.log.info 'Passed' Origen.log.info '------' passed_jobs.each { |j| print_details_of(j) } end if [:type] == :all || [:type] == :failed Origen.log.info '' Origen.log.info 'Failed' Origen.log.info '------' failed_jobs.each { |j| print_details_of(j) } end end end |
#print_details_of(job) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/origen/application/lsf_manager.rb', line 165 def print_details_of(job) Origen.log.info "#{job[:command]} #{job[:switches]}".gsub(' --exec_remote', '') Origen.log.info "ID: #{job[:id]}" Origen.log.info "Submitted: #{time_ago(job[:submitted_at])}" Origen.log.info '' end |
#print_status(options = {}) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/origen/application/lsf_manager.rb', line 75 def print_status( = {}) = { print_insructions: true }.merge() if [:verbose] print_details() end Origen.log.info '' Origen.log.info 'LSF Status' Origen.log.info '----------' Origen.log.info "Queuing: #{queuing_jobs.size}" Origen.log.info "Running: #{running_jobs.size}" Origen.log.info "Lost: #{lost_jobs.size}" Origen.log.info '' Origen.log.info "Passed: #{passed_jobs.size}" Origen.log.info "Failed: #{failed_jobs.size}" Origen.log.info '' if [:print_insructions] Origen.log.info 'Common tasks' Origen.log.info '------------' if queuing_jobs.size > 0 Origen.log.info 'Queuing' Origen.log.info ' Show details: origen l -v -t queuing' Origen.log.info ' Re-submit: origen l -r -t queuing' end if running_jobs.size > 0 Origen.log.info 'Running' Origen.log.info ' Show details: origen l -v -t running' Origen.log.info ' Re-submit: origen l -r -t running' end if lost_jobs.size > 0 Origen.log.info 'Lost' Origen.log.info ' Show details: origen l -v -t lost' Origen.log.info ' Re-submit: origen l -r -t lost' end if passed_jobs.size > 0 Origen.log.info 'Passed' Origen.log.info ' Build log: origen l -l' end if failed_jobs.size > 0 Origen.log.info 'Failed' Origen.log.info ' Show details: origen l -v -t failed' Origen.log.info ' Re-submit: origen l -r -t failed' end Origen.log.info '' Origen.log.info 'Reset the LSF manager (clear all jobs): origen lsf -c -t all' Origen.log.info '' end end |
#queuing_jobs ⇒ Object
546 547 548 |
# File 'lib/origen/application/lsf_manager.rb', line 546 def queuing_jobs @queuing_jobs ||= [] end |
#remote_jobs ⇒ Object
475 476 477 |
# File 'lib/origen/application/lsf_manager.rb', line 475 def remote_jobs @remote_jobs ||= restore_remote_jobs || {} end |
#remote_jobs_file ⇒ Object
17 18 19 |
# File 'lib/origen/application/lsf_manager.rb', line 17 def remote_jobs_file "#{Origen.root}/.lsf/remote_jobs" end |
#restore_remote_jobs ⇒ Object
597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/origen/application/lsf_manager.rb', line 597 def restore_remote_jobs if File.exist?(remote_jobs_file) File.open(remote_jobs_file) do |f| begin Marshal.load(f) rescue nil end end end end |
#resubmit(options) ⇒ Object
Resubmit jobs
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/origen/application/lsf_manager.rb', line 222 def resubmit() if [:type] if [:type] == :all remote_jobs.each do |_id, job| resubmit_job(job) end else send("#{[:type]}_jobs").each do |job| resubmit_job(job) end end else resubmit_job(remote_jobs[[:id]]) end end |
#resubmit_job(job) ⇒ Object
355 356 357 358 359 360 361 362 363 364 |
# File 'lib/origen/application/lsf_manager.rb', line 355 def resubmit_job(job) [log_file(job[:id]), passed_file(job[:id]), failed_file(job[:id]), started_file(job[:id])].each do |file| FileUtils.rm_f(file) if File.exist?(file) end job[:lsf_id] = Origen.app.lsf.submit(command_prefix(job[:id], job[:dependents_ids]) + job[:command] + job[:switches], dependents: job[:dependents_lsf_ids]) job[:status] = nil job[:completed_at] = nil job[:submitted_at] = Time.now job[:submissions] += 1 end |
#running_jobs ⇒ Object
542 543 544 |
# File 'lib/origen/application/lsf_manager.rb', line 542 def running_jobs @running_jobs ||= [] end |
#save_remote_jobs ⇒ Object
613 614 615 616 617 |
# File 'lib/origen/application/lsf_manager.rb', line 613 def save_remote_jobs File.open(remote_jobs_file, 'w') do |f| Marshal.dump(@remote_jobs, f) end end |
#started_file(id) ⇒ Object
324 325 326 |
# File 'lib/origen/application/lsf_manager.rb', line 324 def started_file(id) "#{log_file_directory}/#{log_file_name(id)}.started" end |
#stats ⇒ Object
238 239 240 |
# File 'lib/origen/application/lsf_manager.rb', line 238 def stats Origen.app.stats end |
#submit_job(command, options = {}) ⇒ Object
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/origen/application/lsf_manager.rb', line 366 def submit_job(command, = {}) = { lsf_option_string: '' }.merge() switches = [' ', [:lsf_option_string], (command)].flatten.compact.join(' ') id = generate_job_id dependents_ids = extract_ids([[:depend], [:depends], [:dependent], [:dependents]].flatten.compact) dependents_lsf_ids = dependents_ids.map { |dep_id| remote_jobs[dep_id][:lsf_id] } lsf_id = Origen.app.lsf.submit(command_prefix(id, dependents_ids) + command + switches, dependents: dependents_lsf_ids) job_attrs = { id: id, lsf_id: lsf_id, command: command, submitted_at: Time.now, submissions: 1, switches: switches, dependents_ids: dependents_ids, dependents_lsf_ids: dependents_lsf_ids } remote_jobs[id] = job_attrs end |
#submit_origen_job(cmd, options = {}) ⇒ Object
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 |
# File 'lib/origen/application/lsf_manager.rb', line 392 def submit_origen_job(cmd, = {}) if [:action] action = [:action] == :pattern ? ' generate' : " #{[:action]}" else action = '' end str = "#{action} #{cmd}".strip str.sub('origen ', '') if str =~ /^origen / # Append the --exec_remote switch to all Origen commands, this allows command # processing to be altered based on whether it is running locally or # remotely by testing Origen.running_remotely? str += ' --exec_remote' submit_job("origen #{str}", ) end |
#time_ago(time) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/origen/application/lsf_manager.rb', line 172 def time_ago(time) seconds = (Time.now - time).to_i if seconds < 60 unit = 'second' number = seconds elsif seconds < 3600 unit = 'minute' number = seconds / 60 elsif seconds < 86_400 unit = 'hour' number = seconds / 3600 else unit = 'day' number = seconds / 86_400 end "#{number} #{unit}#{number > 1 ? 's' : ''} ago" end |
#wait_for_completion(options = {}) ⇒ Object
Waits for all jobs to complete, will retry lost jobs (optionally failed jobs).
Alternatively supply an :id or an array of :ids to wait only for specific job(s) to complete.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/origen/application/lsf_manager.rb', line 26 def wait_for_completion( = {}) = { max_lost_retries: 10, max_fail_retries: 0, poll_duration_in_seconds: 10, timeout_in_seconds: 3600 }.merge() [:start_time] ||= Time.now if Time.now - [:start_time] < [:timeout_in_seconds] # When waiting for ids we will hold by monitoring for the result # files directly, rather than using the generatic classify routine. # This is because the most common use case for this is when jobs # are idling remotely on the LSF and don't want to run into contention # issues when multiple processes try to classify/save the status. if [:id] || [:ids] ids = extract_ids([[:id], [:ids]].flatten.compact) if ids.any? { |id| job_running?(id) } sleep [:poll_duration_in_seconds] wait_for_completion() end else classify_jobs print_status(print_insructions: false) sleep [:poll_duration_in_seconds] classify_jobs resumitted = false lost_jobs.each do |job| if job[:submissions] < [:max_lost_retries] + 1 resubmit_job(job) resumitted = true end end failed_jobs.each do |job| if job[:submissions] < [:max_fail_retries] + 1 resubmit_job(job) resumitted = true end end classify_jobs if outstanding_jobs? || resumitted wait_for_completion() else print_status end end end end |