simplews 1.8.3 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rake_pipeline.rb +47 -33
 - data/lib/simplews/jobs.rb +2 -1
 - data/lib/simplews/rake.rb +4 -2
 - metadata +2 -2
 
    
        data/lib/rake_pipeline.rb
    CHANGED
    
    | 
         @@ -118,56 +118,65 @@ module Rake::Pipeline 
     | 
|
| 
       118 
118 
     | 
    
         
             
                Rake::Pipeline::Step.step_descriptions
         
     | 
| 
       119 
119 
     | 
    
         
             
              end
         
     | 
| 
       120 
120 
     | 
    
         | 
| 
       121 
     | 
    
         
            -
             
     | 
| 
       122 
121 
     | 
    
         
             
              def step_dependencies(*args)
         
     | 
| 
       123 
122 
     | 
    
         
             
                Rake::Pipeline::Step.step_dependencies(*args)
         
     | 
| 
       124 
123 
     | 
    
         
             
              end
         
     | 
| 
       125 
124 
     | 
    
         | 
| 
       126 
     | 
    
         
            -
              def  
     | 
| 
       127 
     | 
    
         
            -
                 
     | 
| 
      
 125 
     | 
    
         
            +
              def step_dir(step = nil, filename = nil)
         
     | 
| 
      
 126 
     | 
    
         
            +
                filename ||= @@current_task.name
         
     | 
| 
      
 127 
     | 
    
         
            +
                info = Rake::Pipeline::Step.parse_filename(filename)
         
     | 
| 
      
 128 
     | 
    
         
            +
                "%s/%s" % [info[:prefix], step || info[:step]]
         
     | 
| 
      
 129 
     | 
    
         
            +
              end
         
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
              def input_filename(task = nil, step = nil)
         
     | 
| 
      
 132 
     | 
    
         
            +
                task ||= @@current_task
         
     | 
| 
      
 133 
     | 
    
         
            +
                if step.nil?
         
     | 
| 
      
 134 
     | 
    
         
            +
                  task.prerequisites.first
         
     | 
| 
      
 135 
     | 
    
         
            +
                else
         
     | 
| 
      
 136 
     | 
    
         
            +
                  File.join(step_dir(step, task.name), job_name)
         
     | 
| 
      
 137 
     | 
    
         
            +
                end
         
     | 
| 
      
 138 
     | 
    
         
            +
              end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
              def output_filename(task = nil)
         
     | 
| 
      
 141 
     | 
    
         
            +
                task ||= @@current_task
         
     | 
| 
      
 142 
     | 
    
         
            +
                task.name
         
     | 
| 
      
 143 
     | 
    
         
            +
              end
         
     | 
| 
      
 144 
     | 
    
         
            +
             
     | 
| 
      
 145 
     | 
    
         
            +
             
     | 
| 
      
 146 
     | 
    
         
            +
              def infile(task, step = nil,  &block)
         
     | 
| 
      
 147 
     | 
    
         
            +
                filename = input_filename(task, step)
         
     | 
| 
      
 148 
     | 
    
         
            +
                File.open(filename) do |f|
         
     | 
| 
       128 
149 
     | 
    
         
             
                  block.call(f)
         
     | 
| 
       129 
150 
     | 
    
         
             
                end
         
     | 
| 
       130 
151 
     | 
    
         
             
              end
         
     | 
| 
       131 
152 
     | 
    
         | 
| 
       132 
     | 
    
         
            -
              def outfile( 
     | 
| 
       133 
     | 
    
         
            -
                 
     | 
| 
      
 153 
     | 
    
         
            +
              def outfile(task, &block)
         
     | 
| 
      
 154 
     | 
    
         
            +
                filename = output_filename(task)
         
     | 
| 
      
 155 
     | 
    
         
            +
                File.open(filename, 'w') do |f|
         
     | 
| 
       134 
156 
     | 
    
         
             
                  block.call(f)
         
     | 
| 
       135 
157 
     | 
    
         
             
                end
         
     | 
| 
       136 
158 
     | 
    
         
             
              end
         
     | 
| 
       137 
159 
     | 
    
         | 
| 
       138 
     | 
    
         
            -
              def load_input( 
     | 
| 
       139 
     | 
    
         
            -
                 
     | 
| 
       140 
     | 
    
         
            -
                   
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
                   
     | 
| 
       143 
     | 
    
         
            -
                     
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
                    else
         
     | 
| 
       146 
     | 
    
         
            -
                      f.read
         
     | 
| 
       147 
     | 
    
         
            -
                    end
         
     | 
| 
       148 
     | 
    
         
            -
                  }
         
     | 
| 
       149 
     | 
    
         
            -
                else
         
     | 
| 
       150 
     | 
    
         
            -
                  return nil if t.prerequisites.first.nil?
         
     | 
| 
       151 
     | 
    
         
            -
                  infile(t){|f| 
         
     | 
| 
       152 
     | 
    
         
            -
                    if is_binary?(f)
         
     | 
| 
       153 
     | 
    
         
            -
                      Marshal.load(f) 
         
     | 
| 
       154 
     | 
    
         
            -
                    else
         
     | 
| 
       155 
     | 
    
         
            -
                      f.read
         
     | 
| 
       156 
     | 
    
         
            -
                    end
         
     | 
| 
       157 
     | 
    
         
            -
                  }
         
     | 
| 
      
 160 
     | 
    
         
            +
              def load_input(task, step = nil)
         
     | 
| 
      
 161 
     | 
    
         
            +
                infile(task, step) do |f|
         
     | 
| 
      
 162 
     | 
    
         
            +
                  if is_binary?(f)
         
     | 
| 
      
 163 
     | 
    
         
            +
                    Marshal.load(f) 
         
     | 
| 
      
 164 
     | 
    
         
            +
                  else
         
     | 
| 
      
 165 
     | 
    
         
            +
                    f.read
         
     | 
| 
      
 166 
     | 
    
         
            +
                  end
         
     | 
| 
       158 
167 
     | 
    
         
             
                end
         
     | 
| 
       159 
168 
     | 
    
         
             
              end
         
     | 
| 
      
 169 
     | 
    
         
            +
                 
         
     | 
| 
       160 
170 
     | 
    
         | 
| 
       161 
     | 
    
         
            -
              def save_output( 
     | 
| 
      
 171 
     | 
    
         
            +
              def save_output(task, output)
         
     | 
| 
       162 
172 
     | 
    
         
             
                case 
         
     | 
| 
       163 
173 
     | 
    
         
             
                when output.nil?
         
     | 
| 
       164 
174 
     | 
    
         
             
                  nil
         
     | 
| 
       165 
175 
     | 
    
         
             
                when String === output
         
     | 
| 
       166 
     | 
    
         
            -
                  outfile( 
     | 
| 
      
 176 
     | 
    
         
            +
                  outfile(task){|f| f.write output } 
         
     | 
| 
       167 
177 
     | 
    
         
             
                else
         
     | 
| 
       168 
     | 
    
         
            -
                  outfile( 
     | 
| 
      
 178 
     | 
    
         
            +
                  outfile(task){|f| f.write Marshal.dump(output) } 
         
     | 
| 
       169 
179 
     | 
    
         
             
                end
         
     | 
| 
       170 
     | 
    
         
            -
             
     | 
| 
       171 
180 
     | 
    
         
             
              end
         
     | 
| 
       172 
181 
     | 
    
         | 
| 
       173 
182 
     | 
    
         
             
              # We cannot load the input variable before the block.call, so we need another method
         
     | 
| 
         @@ -179,7 +188,11 @@ module Rake::Pipeline 
     | 
|
| 
       179 
188 
     | 
    
         | 
| 
       180 
189 
     | 
    
         
             
              if defined? SimpleWS::Jobs
         
     | 
| 
       181 
190 
     | 
    
         
             
                def method_missing(symbol, *args)
         
     | 
| 
       182 
     | 
    
         
            -
                  $_current_job. 
     | 
| 
      
 191 
     | 
    
         
            +
                  if $_current_job.methods.include? symbol.to_s
         
     | 
| 
      
 192 
     | 
    
         
            +
                    $_current_job.send(symbol, *args)
         
     | 
| 
      
 193 
     | 
    
         
            +
                  else
         
     | 
| 
      
 194 
     | 
    
         
            +
                    raise "Method #{ symbol } not found"
         
     | 
| 
      
 195 
     | 
    
         
            +
                  end
         
     | 
| 
       183 
196 
     | 
    
         
             
                end
         
     | 
| 
       184 
197 
     | 
    
         
             
              else
         
     | 
| 
       185 
198 
     | 
    
         
             
                # Announce steps
         
     | 
| 
         @@ -194,11 +207,12 @@ module Rake::Pipeline 
     | 
|
| 
       194 
207 
     | 
    
         
             
                  Rake::Pipeline::Info.save_info(@@current_task, info)
         
     | 
| 
       195 
208 
     | 
    
         
             
                  info
         
     | 
| 
       196 
209 
     | 
    
         
             
                end
         
     | 
| 
      
 210 
     | 
    
         
            +
             
     | 
| 
      
 211 
     | 
    
         
            +
                def job_name
         
     | 
| 
      
 212 
     | 
    
         
            +
                  File.basename(@@current_task.name)
         
     | 
| 
      
 213 
     | 
    
         
            +
                end
         
     | 
| 
       197 
214 
     | 
    
         
             
              end
         
     | 
| 
       198 
215 
     | 
    
         | 
| 
       199 
     | 
    
         
            -
              
         
     | 
| 
       200 
     | 
    
         
            -
              
         
     | 
| 
       201 
     | 
    
         
            -
              
         
     | 
| 
       202 
216 
     | 
    
         
             
              # Define a new step, it depends on the previously defined by default. It
         
     | 
| 
       203 
217 
     | 
    
         
             
              # saves the output of the block so it can be loaded by the input method of
         
     | 
| 
       204 
218 
     | 
    
         
             
              # the next step
         
     | 
    
        data/lib/simplews/jobs.rb
    CHANGED
    
    
    
        data/lib/simplews/rake.rb
    CHANGED
    
    | 
         @@ -18,7 +18,7 @@ class SimpleWS::Jobs::Scheduler::Job 
     | 
|
| 
       18 
18 
     | 
    
         
             
              # 'execute' method of the Rake::Tasks class method execute is monkey-patched
         
     | 
| 
       19 
19 
     | 
    
         
             
              # to log the steps. Since this is executed on a new process, there should be
         
     | 
| 
       20 
20 
     | 
    
         
             
              # no side-effects from the patching.
         
     | 
| 
       21 
     | 
    
         
            -
              def rake(rakefile = "Rakefile")
         
     | 
| 
      
 21 
     | 
    
         
            +
              def rake(rakefile = "Rakefile", target = nil)
         
     | 
| 
       22 
22 
     | 
    
         
             
                Rake::Task.class_eval <<-'EOC'
         
     | 
| 
       23 
23 
     | 
    
         
             
                  alias_method :old_execute, :execute
         
     | 
| 
       24 
24 
     | 
    
         
             
                  def execute(*args)
         
     | 
| 
         @@ -60,10 +60,12 @@ class SimpleWS::Jobs::Scheduler::Job 
     | 
|
| 
       60 
60 
     | 
    
         
             
                end
         
     | 
| 
       61 
61 
     | 
    
         | 
| 
       62 
62 
     | 
    
         
             
                files = result_filenames
         
     | 
| 
      
 63 
     | 
    
         
            +
                target ||= files.first
         
     | 
| 
       63 
64 
     | 
    
         | 
| 
       64 
65 
     | 
    
         
             
                $_current_job = self
         
     | 
| 
       65 
66 
     | 
    
         
             
                $_step_descriptions = @step_descriptions || {}
         
     | 
| 
       66 
     | 
    
         
            -
             
     | 
| 
      
 67 
     | 
    
         
            +
             
     | 
| 
      
 68 
     | 
    
         
            +
                Rake::Task[target].invoke
         
     | 
| 
       67 
69 
     | 
    
         
             
              end
         
     | 
| 
       68 
70 
     | 
    
         | 
| 
       69 
71 
     | 
    
         
             
            end
         
     | 
    
        metadata
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            --- !ruby/object:Gem::Specification 
         
     | 
| 
       2 
2 
     | 
    
         
             
            name: simplews
         
     | 
| 
       3 
3 
     | 
    
         
             
            version: !ruby/object:Gem::Version 
         
     | 
| 
       4 
     | 
    
         
            -
              version: 1. 
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.9.0
         
     | 
| 
       5 
5 
     | 
    
         
             
            platform: ruby
         
     | 
| 
       6 
6 
     | 
    
         
             
            authors: 
         
     | 
| 
       7 
7 
     | 
    
         
             
            - Miguel Vazquez
         
     | 
| 
         @@ -9,7 +9,7 @@ autorequire: 
     | 
|
| 
       9 
9 
     | 
    
         
             
            bindir: bin
         
     | 
| 
       10 
10 
     | 
    
         
             
            cert_chain: []
         
     | 
| 
       11 
11 
     | 
    
         | 
| 
       12 
     | 
    
         
            -
            date: 2010- 
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2010-02-15 00:00:00 +01:00
         
     | 
| 
       13 
13 
     | 
    
         
             
            default_executable: 
         
     | 
| 
       14 
14 
     | 
    
         
             
            dependencies: 
         
     | 
| 
       15 
15 
     | 
    
         
             
            - !ruby/object:Gem::Dependency 
         
     |