Class: Cagnut::JobManage

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Singleton
Defined in:
lib/cagnut/job_manage.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run_localObject



14
15
16
# File 'lib/cagnut/job_manage.rb', line 14

def run_local
  instance.run_local
end

.submit(job_script, job_name, opts) ⇒ Object



10
11
12
# File 'lib/cagnut/job_manage.rb', line 10

def submit job_script, job_name, opts
  instance.submit job_script, job_name, opts
end

Instance Method Details

#export_command(command) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/cagnut/job_manage.rb', line 34

def export_command command
  file = File.join jobs_dir, "submit_command_#{sample_name}.jobs"
  File.open(file, 'a') do |f|
    f.puts <<-BASH.strip_heredoc
      #{command}
      #{wait_local}
    BASH
  end
  File.chmod(0700, file)
end

#full_command(job_script, job_name, opts) ⇒ Object



25
26
27
28
# File 'lib/cagnut/job_manage.rb', line 25

def full_command job_script, job_name, opts
  return super if defined?(super) && !run_local?
  local job_script
end

#local(job_script) ⇒ Object



45
46
47
48
49
# File 'lib/cagnut/job_manage.rb', line 45

def local job_script
  %(nohup #{jobs_dir}/#{job_script}.sh \
  > #{jobs_dir}/#{job_script}.std \
  2>#{jobs_dir}/#{job_script}.err &)
end

#run_localObject



51
52
53
54
55
# File 'lib/cagnut/job_manage.rb', line 51

def run_local
  return unless run_local?
  %(& echo $! >> #{jobs_dir}/submit_job_#{sample_name}.ids
    wait $!)
end

#run_local?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cagnut/job_manage.rb', line 30

def run_local?
  cluster.blank? || cluster['system'] == 'Local'
end

#submit(job_script, job_name, opts) ⇒ Object



19
20
21
22
23
# File 'lib/cagnut/job_manage.rb', line 19

def submit job_script, job_name, opts
  command = full_command job_script, job_name, opts
  export_command command
  puts command
end

#wait_localObject



57
58
59
60
# File 'lib/cagnut/job_manage.rb', line 57

def wait_local
  return unless run_local?
  'wait $!'
end