Class: JobStep
- Inherits:
-
Object
- Object
- JobStep
- Defined in:
- lib/rpipe.rb
Direct Known Subclasses
Constant Summary collapse
- COLLISION_POLICY =
options – :panic, :destroy, :overwrite
:panic
Instance Attribute Summary collapse
-
#collision_policy ⇒ Object
Returns the value of attribute collision_policy.
-
#libdir ⇒ Object
Returns the value of attribute libdir.
-
#origdir ⇒ Object
Returns the value of attribute origdir.
-
#procdir ⇒ Object
Returns the value of attribute procdir.
-
#rawdir ⇒ Object
Returns the value of attribute rawdir.
-
#spmdir ⇒ Object
Returns the value of attribute spmdir.
-
#statsdir ⇒ Object
Returns the value of attribute statsdir.
-
#step ⇒ Object
Returns the value of attribute step.
-
#subid ⇒ Object
Returns the value of attribute subid.
Instance Method Summary collapse
- #check_instance_vars(*args) ⇒ Object
- #default_spmdir ⇒ Object
-
#include_custom_methods(module_name) ⇒ Object
Dynamically load custom methods for advanced processing.
-
#initialize(workflow_spec, job_spec) ⇒ JobStep
constructor
Intialize with two configuration option hashes - workflow_spec and job_spec.
-
#job_requires(*args) ⇒ Object
Check for required keys in instance variables.
-
#setup_directory(path, logging_tag) ⇒ Object
Setup directory path according to collision policy.
- #validate_existence_of(*args) ⇒ Object
Constructor Details
#initialize(workflow_spec, job_spec) ⇒ JobStep
Intialize with two configuration option hashes - workflow_spec and job_spec
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rpipe.rb', line 33 def initialize(workflow_spec, job_spec) # allow jobspec to override the workflow spec @subid = job_spec['subid'] || workflow_spec['subid'] @rawdir = job_spec['rawdir'] || workflow_spec['rawdir'] @origdir = job_spec['origdir'] || workflow_spec['origdir'] @procdir = job_spec['procdir'] || workflow_spec['procdir'] @statsdir = job_spec['statsdir'] || workflow_spec['statsdir'] @spmdir = job_spec['spmdir'] || workflow_spec['spmdir'] || default_spmdir @scans = job_spec['scans'] || workflow_spec['scans'] @scan_labels = job_spec['scan_labels'] || workflow_spec['scan_labels'] @collision_policy = (job_spec['collision'] || workflow_spec['collision'] || COLLISION_POLICY).to_sym @step = job_spec['step'] @method = job_spec['method'] include_custom_methods(@method) @libdir = File.dirname(Pathname.new(__FILE__).realpath) job_requires 'subid' end |
Instance Attribute Details
#collision_policy ⇒ Object
Returns the value of attribute collision_policy.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def collision_policy @collision_policy end |
#libdir ⇒ Object
Returns the value of attribute libdir.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def libdir @libdir end |
#origdir ⇒ Object
Returns the value of attribute origdir.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def origdir @origdir end |
#procdir ⇒ Object
Returns the value of attribute procdir.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def procdir @procdir end |
#rawdir ⇒ Object
Returns the value of attribute rawdir.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def rawdir @rawdir end |
#spmdir ⇒ Object
Returns the value of attribute spmdir.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def spmdir @spmdir end |
#statsdir ⇒ Object
Returns the value of attribute statsdir.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def statsdir @statsdir end |
#step ⇒ Object
Returns the value of attribute step.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def step @step end |
#subid ⇒ Object
Returns the value of attribute subid.
30 31 32 |
# File 'lib/rpipe.rb', line 30 def subid @subid end |
Instance Method Details
#check_instance_vars(*args) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/rpipe.rb', line 110 def check_instance_vars(*args) undefined_vars = [] args.each do |arg| unless instance_variable_defined?("@" + arg) && eval("@" + arg).nil? == false undefined_vars << arg end end unless undefined_vars.size == 0 yield undefined_vars end end |
#default_spmdir ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/rpipe.rb', line 129 def default_spmdir spmdirs = %w{/Applications/spm/spm8/spm8_current /apps/spm/spm8_current} spmdirs.each do |dir| return dir if File.directory? dir end raise IOError, "Couldn't find default SPM directory in #{spmdirs.join("; ")}." end |
#include_custom_methods(module_name) ⇒ Object
Dynamically load custom methods for advanced processing.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rpipe.rb', line 53 def include_custom_methods(module_name) if module_name.nil? or ['default','wadrc'].include?(module_name) # do nothing, use default implementation else # Search the load path and require a file named after the custom method. # Include methods contained in the custom method module. # Ensure it's named properly according to file convention or it won't be correctly included. begin require module_name extend self.class.const_get(module_name.dot_camelize) rescue LoadError => e puts "Unable to find the specified method #{module_name}" puts "Please either use a standard preprocessing step or put a method in app/methods/#{module_name}.rb" puts "Looking in: #{$LOAD_PATH.join(":")}" raise e rescue NameError => e $Log.error "Unable to include a module #{module_name.dot_camelize} (for custom #{@step} step)." puts "Please check app/methods/#{module_name}.rb and ensure that you declared a module named _exactly_ #{module_name.dot_camelize}." puts raise e end end end |
#job_requires(*args) ⇒ Object
Check for required keys in instance variables.
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rpipe.rb', line 97 def job_requires(*args) check_instance_vars *args do |missing_vars| error = " Warning: Misconfiguration detected. You are missing the following required variables from your spec file: #{missing_vars.collect { |var| "\t - #{var} \n" } } " puts error raise ScriptError, "Missing Vars: #{missing_vars.join(", ")}" end end |
#setup_directory(path, logging_tag) ⇒ Object
Setup directory path according to collision policy.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/rpipe.rb', line 79 def setup_directory(path, logging_tag) if File.exist?(path) if @collision_policy == :destroy puts "#{logging_tag} :: Deleting directory #{path}" FileUtils.rm_rf(path) FileUtils.mkdir_p(path) elsif @collision_policy == :overwrite puts "#{logging_tag} :: Overwriting inside directory #{path}" else raise(IOError, "Directory already exists, exiting: #{path}") end else puts "#{logging_tag} :: Creating new directory #{path}" FileUtils.mkdir_p(path) end end |
#validate_existence_of(*args) ⇒ Object
123 124 125 126 127 |
# File 'lib/rpipe.rb', line 123 def validate_existence_of(*args) missing_files = [] args.flatten.collect { |file| missing_files << file unless File.exist?(file) } raise ScriptError, "Missing files: #{missing_files.join(", ")}" unless missing_files.empty? end |