Module: SchedulerJob
- Extended by:
- SchedulerJob
- Included in:
- LSF, PBS, SLURM, SchedulerJob
- Defined in:
- lib/scout/workflow/deployment/scheduler/job.rb
Instance Attribute Summary collapse
-
#batch_base_dir ⇒ Object
Returns the value of attribute batch_base_dir.
Class Method Summary collapse
- .batch_dir_for_id(batch_base_dir, id) ⇒ Object
- .batch_options(job, options) ⇒ Object
- .batch_system_variables ⇒ Object
- .cleanup_environment(options = {}) ⇒ Object
- .coda(options) ⇒ Object
- .exec_cmd(job, options = {}) ⇒ Object
- .execute(options) ⇒ Object
- .follow_job(batch_dir, tail = true) ⇒ Object
- .header(options) ⇒ Object
- .hold_dependencies(job, batch_job) ⇒ Object
- .job_queued(job) ⇒ Object
- .job_template(job, options = {}) ⇒ Object
- .jobs ⇒ Object
- .load_conda(env = nil) ⇒ Object
- .load_modules(modules = []) ⇒ Object
- .meta_data(options) ⇒ Object
- .prepare_environment(options = {}) ⇒ Object
- .prepare_submision(template, batch_dir, clean_batch_job = false, batch_dependencies = []) ⇒ Object
- .run_job(job, options = {}) ⇒ Object
- .scout_job_exec_cmd(job, options) ⇒ Object
- .sync_environment(options = {}) ⇒ Object
- .system ⇒ Object
- .wait_for_job(batch_dir, time = 1) ⇒ Object
Instance Attribute Details
#batch_base_dir ⇒ Object
Returns the value of attribute batch_base_dir.
3 4 5 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 3 def batch_base_dir @batch_base_dir end |
Class Method Details
.batch_dir_for_id(batch_base_dir, id) ⇒ Object
550 551 552 553 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 550 def batch_dir_for_id(batch_base_dir, id) job_id_file = Dir.glob(File.join(batch_base_dir, '*/job.id')).select{|f| Open.read(f).strip == id.to_s }.first job_id_file ? File.dirname(job_id_file) : nil end |
.batch_options(job, options) ⇒ Object
123 124 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 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 123 def (job, ) IndiferentHash.setup() = IndiferentHash.setup({}) keys = [ :queue, :account, :partition, :exclusive, :highmem, :time, :nodes, :task_cpus, :mem, :mem_per_cpu, :gres, :lua_modules, :conda, :constraints, :licenses, :batch_dir, :batch_name, :contain, :sync, :contain_and_sync, :copy_image, :launcher, :development, :env_cmd, :env, :manifest, :user_group, :wipe_container, :workdir, :purge_deps, :singularity, :singularity_img, :singularity_mounts, :singularity_opt_dir, :singularity_ruby_inline ] keys.each do |key| next if [key].nil? [key] = IndiferentHash. , key end batch_dir = [:batch_dir] batch_name = File.basename(batch_dir) inputs_dir = File.join(batch_dir, 'inputs_dir') keys_from_config = [ :queue, :highmem, :exclusive, :launcher, :development, :env_cmd, :env, :user_group, :singularity_img, :singularity_mounts, :singularity_opt_dir, :singularity_ruby_inline, :singularity ] keys_from_config.each do |key| next unless .include? key default_value = Scout::Config.get(key, "batch_#{key}", "batch") next if default_value.nil? IndiferentHash.add_defaults , default_value end user = [:user] ||= ENV['USER'] || `whoami`.strip group = [:group] ||= File.basename(File.dirname(ENV['HOME'])) [:scratch_group_dir] = File.join('/gpfs/scratch/', group) [:projects_group_dir] = File.join('/gpfs/projects/', group) [:singularity] = true if [:singularity_img] if [:contain_and_sync] if [:contain].nil? contain_base = Scout::Config.get(:contain_base_dir, :batch_contain, :batch, :default => "/scratch/tmp/scout-[USER]") contain_base = contain_base.sub('[USER]', user) random_file = TmpFile.random_name [:contain] = File.join(contain_base, random_file) end [:sync] ||= "~/.scout/var/jobs" [:wipe_container] ||= 'post' end if [:contain] && ! [:hardened] [:workdir_all] = [:contain] end IndiferentHash.add_defaults , :batch_name => batch_name, :inputs_dir => inputs_dir, :nodes => 1, :step_path => job.path, :task_cpus => 1, :time => '2min', :env => {'JDK_JAVA_OPTIONS' => "-Xms1g -Xmx${MAX_MEMORY}m"}, :singularity_img => ENV["SINGULARITY_IMG"] || "~/scout.singularity.img", :singularity_ruby_inline => ENV["SINGULARITY_RUBY_INLINE"] || "~/.singularity_ruby_inline", :singularity_opt_dir => ENV["SINGULARITY_OPT_DIR"] || "~/singularity_opt", :workdir => Dir.pwd exec_cmd = exec_cmd(job, ) scout_cmd = scout_job_exec_cmd(job, ) IndiferentHash.add_defaults , :exec_cmd => exec_cmd, :scout_cmd => scout_cmd batch_dir = [:batch_dir] IndiferentHash.add_defaults , :fout => File.join(batch_dir, 'std.out'), :ferr => File.join(batch_dir, 'std.err'), :fjob => File.join(batch_dir, 'job.id'), :fdep => File.join(batch_dir, 'dependencies.list'), :fcfdep => File.join(batch_dir, 'canfail_dependencies.list'), :fexit => File.join(batch_dir, 'exit.status'), :fsync => File.join(batch_dir, 'sync.log'), :fsexit => File.join(batch_dir, 'sync.status'), :fenv => File.join(batch_dir, 'env.vars'), :fcmd => File.join(batch_dir, 'command.batch') end |
.batch_system_variables ⇒ Object
297 298 299 300 301 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 297 def batch_system_variables "let MAX_MEMORY=\"$(grep MemTotal /proc/meminfo|grep -o \"[[:digit:]]*\") / 1024\"\n EOF\nend\n" |
.cleanup_environment(options = {}) ⇒ Object
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 440 def cleanup_environment( = {}) cleanup_environment = "" cleanup_environment +="if [ $exit_status == '0' ]; then \n\#{options[:exec_cmd]} workflow forget_deps --purge --recursive_purge \"$step_path\" 2>1 >> '\#{options[:fsync]}' \nfi\n EOF\n\n if options[:sync]\n if options[:wipe_container] == 'force'\n cleanup_environment +=<<-EOF\nbatch_erase_contain_dir\n EOF\n elsif options[:wipe_container] == 'post' || options[:wipe_container] == 'both'\n cleanup_environment +=<<-EOF\nif [ $sync_es == '0' -a $empty_contain_dir == 'true' ]; then \nbatch_erase_contain_dir\nfi\n EOF\n end\n end\n cleanup_environment\nend\n" if [:purge_deps] |
.coda(options) ⇒ Object
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 465 def coda() coda ="echo $exit_status > '\#{options[:fexit]}'\n EOF\n\n if options[:sync]\n coda +=<<-EOF\nif [ $sync_es == '0' ]; then\nexit $exit_status\nelse\nexit $sync_es\nfi\n EOF\n else\n coda +=<<-EOF\nexit $exit_status\n EOF\n end\n\n coda\nend\n" |
.exec_cmd(job, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 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 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 13 def exec_cmd(job, = {}) = IndiferentHash.add_defaults , :launcher => :srun if self.system == :slurm launcher, env_cmd, development = IndiferentHash. , :launcher, :env_cmd, :development if contain = [:contain] contain = File.(contain) env_cmd ||= "" env_cmd << " TMPDIR='#{contain}/.scout/tmp' " end if [:singularity] group, user, user_group, scratch_group_dir, projects_group_dir = .values_at :group, :user, :user_group, :scratch_group_dir, :projects_group_dir singularity_img, singularity_opt_dir, singularity_ruby_inline, singularity_mounts = .values_at :singularity_img, :singularity_opt_dir, :singularity_ruby_inline, :singularity_mounts singularity_cmd = %(singularity exec -e -B "#{File.expand_path singularity_opt_dir}":/singularity_opt/ -B "#{File.expand_path singularity_ruby_inline}":"/.singularity_ruby_inline":rw ) if singularity_mounts singularity_mounts.split(",").each do |mount| singularity_cmd += "-B #{ mount } " end end if contain && [:hardened] singularity_cmd << %( -C -H "#{contain}" \ -B "/.singularity_ruby_inline":"#{contain}/.singularity_ruby_inline":rw -B "#{options[:batch_dir]}" \ -B /scratch/tmp \ #{ group != user_group ? "-B /gpfs/projects/#{user_group}" : "" } \ -B #{scratch_group_dir} \ -B #{projects_group_dir} \ -B /apps/ \ -B ~/git:"#{contain}/git":ro \ #{Open.exists?('~/.scout/software/opt/')? '-B ~/.scout/software/opt/:"/opt/":ro' : '' } \ -B ~/.scout:"#{contain}/home/":ro) end singularity_cmd << " #{singularity_img} " end base_cmd = if launcher %(#{launcher} scout) else %(scout) end if env_cmd exec_cmd = %(env #{env_cmd} #{ base_cmd }) else exec_cmd = base_cmd end exec_cmd << "--dev '#{development}'" if development exec_cmd = singularity_cmd + exec_cmd if singularity_cmd exec_cmd end |
.execute(options) ⇒ Object
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 405 def execute() exec_cmd, job_cmd, task_cpus = .values_at :exec_cmd, :scout_cmd, :task_cpus script="step_path=$( \n \#{exec_cmd} \#{job_cmd} --printpath\n)\nexit_status=$?\n\nif [ $exit_status -eq 0 ]; then\n[[ -z $BATCH_JOB_ID ]] || \#{exec_cmd} workflow write_info --recursive --force=false --check_pid \"$step_path\" batch_job $BATCH_JOB_ID\n[[ -z $BATCH_SYSTEM ]] || \#{exec_cmd} workflow write_info --recursive --force=false --check_pid \"$step_path\" batch_system $BATCH_SYSTEM\n\#{exec_cmd} workflow write_info --recursive --force=false --check_pid \"$step_path\" batch_cpus \#{task_cpus}\nfi\n EOF\n\n script\nend\n" |
.follow_job(batch_dir, tail = true) ⇒ Object
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 632 def follow_job(batch_dir, tail = true) fjob = File.join(batch_dir, 'job.id') fout = File.join(batch_dir, 'std.out') ferr = File.join(batch_dir, 'std.err') fexit = File.join(batch_dir, 'exit.status') fstatus = File.join(batch_dir, 'job.status') job = Open.read(fjob).strip if Open.exists?(fjob) if job && ! File.exist?(fexit) begin status_txt = job_status(job) STDERR.puts Log.color(:magenta, "Status [#{job.to_i}]:") STDERR.puts status_txt lines = status_txt.split("\n").length rescue if ! File.exist?(fexit) STDERR.puts Log.color(:magenta, "Job #{job.to_i} not done and not running. STDERR:") STDERR.puts Open.read(ferr) end return end end if File.exist?(fexit) exit_status = Open.read(fexit) if exit_status.to_i == 0 STDERR.puts Log.color(:magenta, "Job #{job} done with exit_status 0. STDOUT:") STDERR.puts Open.read(fout) else STDERR.puts Log.color(:magenta, "Job #{job.to_i} done with exit_status #{exit_status}. STDERR:") STDERR.puts Open.read(ferr) end return end if tail Log.severity = 10 while ! File.exist? fout if job STDERR.puts Log.clear_line(STDERR) STDERR.write Log.color(:magenta, "Waiting for Output") 3.times do STDERR.write Log.color(:magenta, ".") sleep 1 end status_txt = job_status(job) (lines + 1).times do Log.clear_line(STDERR) end Log.clear_line(STDERR) STDERR.puts Log.color(:magenta, "Status [#{job.to_i}]:") STDERR.puts status_txt lines = status_txt.split("\n").length end end STDERR.puts Log.clear_line(STDERR) STDERR.puts Log.color(:magenta, "Output:") begin status_txt = job_status(job) Open.write(fstatus, status_txt) unless status_txt.nil? || status_txt.empty? out = CMD.cmd("tail -f '#{fout}'", :pipe => true) if File.exist?(fout) and not tail == :STDERR err = CMD.cmd("tail -f '#{ferr}'", :pipe => true) if File.exist?(ferr) tout = Thread.new do while c = out.getc STDOUT << c end end terr = Thread.new do while c = err.getc STDERR << c end end sleep 3 while job_queued(job) rescue Aborted ensure begin terr.exit if terr tout.exit if tout err.close if err err.join if err rescue Exception end begin out.close if out out.join if out rescue Exception end end end end |
.header(options) ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 115 def header() header ="#!/bin/bash\n EOF\n\n header\nend\n" |
.hold_dependencies(job, batch_job) ⇒ Object
620 621 622 623 624 625 626 627 628 629 630 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 620 def hold_dependencies(job, batch_job) job.init_info job.set_info :batch_job, batch_job job.set_info :batch_system, self.system job.dependencies.each do |dep| next unless dep.waiting? next if (dep_batch_job = dep.info[:batch_job]) && job_queued(dep_batch_job) hold_dependencies(dep, batch_job) end end |
.job_queued(job) ⇒ Object
730 731 732 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 730 def job_queued(job) job_status(job).split(/[\s\.]+/).include?(job.to_s) end |
.job_template(job, options = {}) ⇒ Object
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 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 487 def job_template(job, = {}) = job, header = self.header() = self.() prepare_environment = self.prepare_environment() execute = self.execute() sync_environment = self.sync_environment() cleanup_environment = self.cleanup_environment() coda = self.coda() "\#{header}\n\n# \#{Log.color :green, \"0. Meta-data\"}\n\#{meta_data}\n\n# \#{Log.color :green, \"1. Prepare environment\"}\n\#{prepare_environment(batch_options)}\nenv > \#{batch_options[:fenv]}\n\n# \#{Log.color :green, \"2. Execute\"}\n\#{execute} \n\n# \#{Log.color :green, \"3. Sync and cleanup environment\"}\n\#{sync_environment}\n\#{cleanup_environment}\n\n# \#{Log.color :green, \"4. Exit\"}\n\#{coda}\n EOF\nend\n" |
.jobs ⇒ Object
734 735 736 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 734 def jobs job_status.split("\n").collect{|l| l.scan(/\d{5,}/).first}.compact.flatten.uniq end |
.load_conda(env = nil) ⇒ Object
283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 283 def load_conda(env = nil) return "" if env.nil? || env.empty? "if ! type conda | grep function &> /dev/null; then\n if [ ! -z $CONDA_EXE ]; then\n source \"$(dirname $(dirname $CONDA_EXE))/etc/profile.d/conda.sh\" &> /dev/null\n fi\nfi\nconda activate \#{ env }\n EOF\nend\n" |
.load_modules(modules = []) ⇒ Object
272 273 274 275 276 277 278 279 280 281 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 272 def load_modules(modules = []) modules = modules.split(/,\s*/) if String === modules str = "" modules.each do |mod| str << "module load #{ mod }" << "\n" end if modules str end |
.meta_data(options) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 259 def () ="#MANIFEST: \#{(options[:manifest] || []) * \", \"}\n#DEPENDENCIES: \#{(options[:dependencies] || []) * \", \"}\n#EXEC_CMD: \#{options[:exec_cmd]}\n#CMD: \#{options[:scout_cmd]}\n#STEP_PATH: \#{options[:step_path]}\n EOF\n\n meta = meta.split(\"\\n\").reject{|line| line =~ /: $/} * \"\\n\"\n meta\nend\n" |
.prepare_environment(options = {}) ⇒ Object
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 303 def prepare_environment( = {}) modules = [:lua_modules] conda = [:conda] prepare_environment = "" functions = "" if contain = [:contain] contain = File.(contain) functions +="function batch_erase_contain_dir(){\n rm -Rfv '\#{contain}' 2>1 >> '\#{options[:fsync]}'\n}\n EOF\n\n prepare_environment +=<<-EOF\nif ls -A '\#{contain}' &> /dev/null ; then\nempty_contain_dir=\"false\"\nelse\nempty_contain_dir=\"true\"\nfi\n EOF\n\n prepare_environment +=<<-EOF if options[:wipe_container] == 'force'\nbatch_erase_contain_dir()\n EOF\n end\n\n if sync = options[:sync]\n source = if options[:singularity]\n File.join(options[:contain], '.scout/var/jobs')\n elsif options[:contain]\n File.join(options[:contain], 'var/jobs')\n else\n '~/.scout/var/jobs/'\n end\n\n source = File.expand_path(source)\n sync = File.expand_path(sync)\n functions +=<<-EOF\nfunction batch_sync_contain_dir(){\nmkdir -p \"$(dirname '\#{sync}')\"\nrsync -avztAXHP --copy-unsafe-links \"\#{source}/\" \"\#{sync}/\" 2>1 >> '\#{options[:fsync]}'\nsync_es=\"$?\" \necho $sync_es > '\#{options[:fsexit]}'\nfind '\#{sync}' -type l -ls | awk '$13 ~ /^\#{sync.gsub('/','\\/')}/ { sub(\"\#{source}\", \"\#{sync}\", $13); print $11, $13 }' | while read A B; do rm $A; ln -s $B $A; done\n}\n EOF\n end\n\n if options[:env]\n prepare_environment +=<<-EOF\n# Set ENV variables \n\#{options[:env].collect{|n,v| \"export \#{n}=\\\"\#{v}\\\"\" } * \"\\n\"}\n EOF\n end\n\n if options[:singularity]\n\n group, user, user_group, scratch_group_dir, projects_group_dir = options.values_at :group, :user, :user_group, :scratch_group_dir, :projects_group_dir\n\n singularity_img, singularity_opt_dir, singularity_ruby_inline = options.values_at :singularity_img, :singularity_opt_dir, :singularity_ruby_inline\n\n prepare_environment +=<<-EOF\n# Load singularity modules\ncommand -v singularity &> /dev/null || module load singularity\nmkdir -p \"\#{File.expand_path singularity_opt_dir}\"\n EOF\n\n if contain && options[:hardened]\n\n prepare_environment +=<<-EOF\n# Prepare container for singularity\nmkdir -p \"\#{contain}\"/.scout/etc/\n\nfor dir in .ruby_inline git home; do\n mkdir -p \"\#{contain}\"/$dir\ndone\n\nfor tmpd in persist_locks produce_locks R_sockets sensiblewrite sensiblewrite_locks step_info_locks tsv_open_locks; do\n mkdir -p \"\#{contain}/.scout/tmp/$tmpd\"\ndone\n\n# Copy environment \ncp ~/.scout/etc/environment \#{contain}/.scout/etc/\n\n# Set search_paths\necho \"singularity: /singularity_opt/{PKGDIR}/{TOPLEVEL}/{SUBPATH}\" > \#{contain}/.scout/etc/search_paths\necho \"scout_user: /home/scout/.scout/{TOPLEVEL}/{SUBPATH}\" >> \#{contain}/.scout/etc/search_paths\necho \"outside_home: \#{contain}/home/{TOPLEVEL}/{SUBPATH}\" >> \#{contain}/.scout/etc/search_paths\necho \"group_projects: \#{projects_group_dir}/{PKGDIR}/{TOPLEVEL}/{SUBPATH}\" >> \#{contain}/.scout/etc/search_paths\necho \"group_scratch: \#{scratch_group_dir}/{PKGDIR}/{TOPLEVEL}/{SUBPATH}\" >> \#{contain}/.scout/etc/search_paths\necho \"user_projects: \#{projects_group_dir}/\#{user}/{PKGDIR}/{TOPLEVEL}/{SUBPATH}\" >> \#{contain}/.scout/etc/search_paths\necho \"user_scratch: \#{scratch_group_dir}/\#{user}/{PKGDIR}/{TOPLEVEL}/{SUBPATH}\" >> \#{contain}/.scout/etc/search_paths\n EOF\n end\n end\n\n [batch_system_variables, load_modules(modules), load_conda(conda), functions, prepare_environment].reject{|s| s.empty? } * \"\\n\"\nend\n" |
.prepare_submision(template, batch_dir, clean_batch_job = false, batch_dependencies = []) ⇒ Object
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 526 def prepare_submision(template, batch_dir, clean_batch_job = false, batch_dependencies = []) Open.mkdir batch_dir fcmd = File.join(batch_dir, 'command.batch') fdep = File.join(batch_dir, 'dependencies.list') fcfdep = File.join(batch_dir, 'canfail_dependencies.list') Open.write(fcmd, template) %w(std.out std.err job.id job.status dependencies.list canfail_dependencies.list exit.status sync.log inputs_dir).each do |filename| path = File.join(batch_dir, filename) Open.rm_rf path if File.exist? path end if clean_batch_job batch_dependencies = [] if batch_dependencies.nil? canfail_dependencies = batch_dependencies.select{|dep| dep =~ /^canfail:(\d+)/ }.collect{|dep| dep.partition(":").last} dependencies = batch_dependencies.reject{|dep| dep =~ /^canfail:(\d+)/ } Open.write(fdep, dependencies * "\n") if dependencies.any? Open.write(fcfdep, canfail_dependencies * "\n") if canfail_dependencies.any? fcmd end |
.run_job(job, options = {}) ⇒ Object
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 555 def run_job(job, = {}) system = self.to_s.split("::").last batch_base_dir, clean_batch_job, remove_batch_dir, procpath, tail, batch_dependencies, dry_run, orchestration_rules_file = IndiferentHash. , :batch_base_dir, :clean_batch_job, :remove_batch_dir, :batch_procpath, :tail, :batch_dependencies, :dry_run, :orchestration_rules, :batch_base_dir => SchedulerJob.batch_base_dir if (batch_job = job.info[:batch_job]) && job_queued(batch_job) Log.info "Job #{job.short_path} already queued in #{batch_job}" return batch_job, batch_dir_for_id(batch_base_dir, batch_job) end if job.running? Log.info "Job #{job.short_path} already running in #{job.info[:pid]}" if job.info[:batch_job] return job.info[:batch_job], batch_dir_for_id(batch_base_dir, batch_job) else return end end workflow = job.workflow task_name = job.task_name = IndiferentHash.setup(Workflow::Orchestrator.job_rules(Batch::Orchestration.orchestration_rules(orchestration_rules_file), job, true)).merge() if orchestration_rules_file workflows_to_load = job.rec_dependencies.select{|d| Step === d}.collect{|d| d.workflow }.compact.collect(&:to_s) - [workflow.to_s] TmpFile.with_file(nil, remove_batch_dir, :tmpdir => batch_base_dir, :prefix => "#{system}_scout_job-#{workflow.to_s}-#{task_name}-") do |batch_dir| IndiferentHash.add_defaults , :batch_dir => batch_dir, :inputs_dir => File.join(batch_dir, "inputs_dir"), :workflows => workflows_to_load.any? ? workflows_to_load.uniq * "," : nil [:procpath_performance] ||= File.join(batch_dir, "procpath##{procpath.gsub(',', '#')}") if procpath template = self.job_template(job, .dup) fcmd = prepare_submision(template, [:batch_dir], clean_batch_job, batch_dependencies) batch_job = run_template(batch_dir, dry_run) hold_dependencies(job, batch_job) unless dry_run return [batch_job, batch_dir] unless tail t_monitor = Thread.new do self.follow_job(batch_dir, :STDERR) end self.wait_for_job(batch_dir) t_monitor.raise Aborted return unless Open.read(File.join(batch_dir, 'exit.status')).strip == '0' path = Open.read(File.join(batch_dir, 'std.out')).strip if Open.exists?(path) && job.path != path Log.info "Path of BATCH job #{path} is different from original job #{job.path}. Stablishing link." Open.ln path, job.path Open.ln path + '.info', job.path + '.info' if Open.exists?(path + '.info') Open.ln path + '.files', job.path + '.files' if Open.exists?(path + '.files') end [batch_job, batch_dir] end end |
.scout_job_exec_cmd(job, options) ⇒ Object
74 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 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 74 def scout_job_exec_cmd(job, ) jobname = job.clean_name workflow = job.workflow task = job.task_name IndiferentHash.add_defaults , :jobname => jobname task = job.task_name if job.recursive_overriden_deps.any? override_deps = job.recursive_overriden_deps. select do |dep| Symbol === dep.overriden end. collect do |dep| o_workflow = dep.overriden_workflow || dep.workflow o_workflow = o_workflow.name if o_workflow.respond_to?(:name) o_task_name = dep.overriden_task || dep.task.name name = [o_workflow, o_task_name] * "#" [name, dep.path] * "=" end.uniq * "," [:override_deps] = override_deps unless override_deps.empty? end # Save inputs into inputs_dir (only if provided) inputs_dir = IndiferentHash. , :inputs_dir if inputs_dir saved = job.save_inputs(inputs_dir) [:load_inputs] = inputs_dir if saved && !saved.nil? && !saved.empty? saved.each do |input| .delete input end if saved end cmds = CMD. .merge(:add_option_dashes => true) "workflow task \#{workflow} \#{task} \#{cmds}\n EOF\nend\n".strip |
.sync_environment(options = {}) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 424 def sync_environment( = {}) sync_environment = "" if [:sync] sync_environment +="if [ $exit_status == '0' ]; then \nbatch_sync_contain_dir\nelse\nsync_es=$exit_status\nfi\n EOF\n end\n\n sync_environment\nend\n" |
.system ⇒ Object
9 10 11 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 9 def system :batch end |
.wait_for_job(batch_dir, time = 1) ⇒ Object
738 739 740 741 742 743 744 745 746 |
# File 'lib/scout/workflow/deployment/scheduler/job.rb', line 738 def wait_for_job(batch_dir, time = 1) fexit = File.join(batch_dir, 'exit.status') fjob = File.join(batch_dir, 'job.id') job = Open.read(fjob) if Open.exists?(fjob) while ! Open.exists?(fexit) sleep time end end |