cascade 0.0.4 → 0.0.5
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/cascade/worker.rb +30 -1
- metadata +1 -1
    
        data/lib/cascade/worker.rb
    CHANGED
    
    | @@ -50,7 +50,13 @@ module Cascade | |
| 50 50 | 
             
                  end
         | 
| 51 51 | 
             
                  write.close
         | 
| 52 52 | 
             
                  result = read.read.strip
         | 
| 53 | 
            -
                  Process. | 
| 53 | 
            +
                  pid, status = Process.wait2(pid)
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                  if status.exitstatus != 0
         | 
| 56 | 
            +
                    job_spec.reload
         | 
| 57 | 
            +
                    job_spec.update_attributes(:last_error => 'Child process failure',
         | 
| 58 | 
            +
                                               :failed_at => Time.now.utc)
         | 
| 59 | 
            +
                  end
         | 
| 54 60 |  | 
| 55 61 | 
             
                  return result == '1'
         | 
| 56 62 | 
             
                end
         | 
| @@ -111,6 +117,29 @@ module Cascade | |
| 111 117 | 
             
                  "#{Socket.gethostname} pid:#{Process.pid}" rescue "pid:#{Process.pid}"
         | 
| 112 118 | 
             
                end
         | 
| 113 119 |  | 
| 120 | 
            +
                MAP_FUNCTION = <<-MAP
         | 
| 121 | 
            +
                  function () {
         | 
| 122 | 
            +
                    emit(this.class_name, {count:1, running:this.locked_at == null ? 0 : 1, failed:this.failed_at == null ? 0 : 1});
         | 
| 123 | 
            +
                  }
         | 
| 124 | 
            +
                MAP
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                REDUCE_FUNCTION = <<-REDUCE
         | 
| 127 | 
            +
                  function (k, v) {
         | 
| 128 | 
            +
                    obj = {count:0, running:0, failed:0};
         | 
| 129 | 
            +
                    for (var i in v) {
         | 
| 130 | 
            +
                      obj.count += v[i].count;
         | 
| 131 | 
            +
                      obj.running += v[i].running;
         | 
| 132 | 
            +
                      obj.failed += v[i].failed;
         | 
| 133 | 
            +
                    }
         | 
| 134 | 
            +
                    return obj;
         | 
| 135 | 
            +
                  }
         | 
| 136 | 
            +
                REDUCE
         | 
| 137 | 
            +
             | 
| 138 | 
            +
                def self.queue
         | 
| 139 | 
            +
                  results = JobSpec.collection.map_reduce MAP_FUNCTION, REDUCE_FUNCTION, :out => {:inline => 1}, :raw => true
         | 
| 140 | 
            +
                  results['results'].inject({}){|m,e| m[e['_id']] = {:count => e['value']['count'].to_i, :running => e['value']['running'].to_i, :failed => e['value']['failed'].to_i}; m }
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
             | 
| 114 143 | 
             
                private
         | 
| 115 144 | 
             
                  def self.find_available(num = 10)
         | 
| 116 145 | 
             
                    right_now = Time.now.utc
         |