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.
Files changed (2) hide show
  1. data/lib/cascade/worker.rb +30 -1
  2. metadata +1 -1
@@ -50,7 +50,13 @@ module Cascade
50
50
  end
51
51
  write.close
52
52
  result = read.read.strip
53
- Process.wait(pid)
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
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: cascade
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrew Timberlake