Commit 0321d1536a3d7abe6cdec6447e94e2bba8796cd6
Exists in
master
and in
1 other branch
Merge pull request #468 from shingara/patch-1
launch a repairDatabase task on clear_resolved
Showing
4 changed files
with
105 additions
and
20 deletions
Show diff stats
Gemfile.lock
@@ -7,9 +7,9 @@ GIT | @@ -7,9 +7,9 @@ GIT | ||
7 | 7 | ||
8 | GIT | 8 | GIT |
9 | remote: https://github.com/rtomayko/tilt.git | 9 | remote: https://github.com/rtomayko/tilt.git |
10 | - revision: 24ea7e9fa5a0624188069393abf033bb8b3f218c | 10 | + revision: 74618967fbed3e206453516b92b47cd9aa922903 |
11 | specs: | 11 | specs: |
12 | - tilt (1.3.6) | 12 | + tilt (1.4.0) |
13 | 13 | ||
14 | GEM | 14 | GEM |
15 | remote: http://rubygems.org/ | 15 | remote: http://rubygems.org/ |
@@ -109,7 +109,7 @@ GEM | @@ -109,7 +109,7 @@ GEM | ||
109 | bcrypt-ruby (~> 3.0) | 109 | bcrypt-ruby (~> 3.0) |
110 | orm_adapter (~> 0.0.3) | 110 | orm_adapter (~> 0.0.3) |
111 | warden (~> 1.1) | 111 | warden (~> 1.1) |
112 | - diff-lcs (1.1.3) | 112 | + diff-lcs (1.2.4) |
113 | email_spec (1.2.1) | 113 | email_spec (1.2.1) |
114 | mail (~> 2.2) | 114 | mail (~> 2.2) |
115 | rspec (~> 2.0) | 115 | rspec (~> 2.0) |
@@ -131,7 +131,7 @@ GEM | @@ -131,7 +131,7 @@ GEM | ||
131 | has_scope (0.5.1) | 131 | has_scope (0.5.1) |
132 | hashie (1.2.0) | 132 | hashie (1.2.0) |
133 | highline (1.6.15) | 133 | highline (1.6.15) |
134 | - hike (1.2.1) | 134 | + hike (1.2.2) |
135 | hipchat (0.4.1) | 135 | hipchat (0.4.1) |
136 | httparty | 136 | httparty |
137 | hoi (0.0.6) | 137 | hoi (0.0.6) |
@@ -188,7 +188,7 @@ GEM | @@ -188,7 +188,7 @@ GEM | ||
188 | bundler (>= 1.0.0) | 188 | bundler (>= 1.0.0) |
189 | rails (>= 3.0.0) | 189 | rails (>= 3.0.0) |
190 | railties (>= 3.0.0) | 190 | railties (>= 3.0.0) |
191 | - multi_json (1.7.0) | 191 | + multi_json (1.7.2) |
192 | multi_xml (0.5.2) | 192 | multi_xml (0.5.2) |
193 | multipart-post (1.1.5) | 193 | multipart-post (1.1.5) |
194 | net-scp (1.0.4) | 194 | net-scp (1.0.4) |
@@ -270,7 +270,7 @@ GEM | @@ -270,7 +270,7 @@ GEM | ||
270 | rdoc (~> 3.4) | 270 | rdoc (~> 3.4) |
271 | thor (>= 0.14.6, < 2.0) | 271 | thor (>= 0.14.6, < 2.0) |
272 | raindrops (0.10.0) | 272 | raindrops (0.10.0) |
273 | - rake (10.0.3) | 273 | + rake (10.0.4) |
274 | rbx-require-relative (0.0.9) | 274 | rbx-require-relative (0.0.9) |
275 | rdoc (3.12.2) | 275 | rdoc (3.12.2) |
276 | json (~> 1.4) | 276 | json (~> 1.4) |
@@ -280,19 +280,21 @@ GEM | @@ -280,19 +280,21 @@ GEM | ||
280 | rest-client (1.6.7) | 280 | rest-client (1.6.7) |
281 | mime-types (>= 1.16) | 281 | mime-types (>= 1.16) |
282 | ri_cal (0.8.8) | 282 | ri_cal (0.8.8) |
283 | - rspec (2.11.0) | ||
284 | - rspec-core (~> 2.11.0) | ||
285 | - rspec-expectations (~> 2.11.0) | ||
286 | - rspec-mocks (~> 2.11.0) | ||
287 | - rspec-core (2.11.1) | ||
288 | - rspec-expectations (2.11.2) | ||
289 | - diff-lcs (~> 1.1.3) | ||
290 | - rspec-mocks (2.11.1) | ||
291 | - rspec-rails (2.11.0) | 283 | + rspec (2.13.0) |
284 | + rspec-core (~> 2.13.0) | ||
285 | + rspec-expectations (~> 2.13.0) | ||
286 | + rspec-mocks (~> 2.13.0) | ||
287 | + rspec-core (2.13.1) | ||
288 | + rspec-expectations (2.13.0) | ||
289 | + diff-lcs (>= 1.1.3, < 2.0) | ||
290 | + rspec-mocks (2.13.1) | ||
291 | + rspec-rails (2.13.1) | ||
292 | actionpack (>= 3.0) | 292 | actionpack (>= 3.0) |
293 | activesupport (>= 3.0) | 293 | activesupport (>= 3.0) |
294 | railties (>= 3.0) | 294 | railties (>= 3.0) |
295 | - rspec (~> 2.11.0) | 295 | + rspec-core (~> 2.13.0) |
296 | + rspec-expectations (~> 2.13.0) | ||
297 | + rspec-mocks (~> 2.13.0) | ||
296 | ruby-debug (0.10.4) | 298 | ruby-debug (0.10.4) |
297 | columnize (>= 0.1) | 299 | columnize (>= 0.1) |
298 | ruby-debug-base (~> 0.10.4.0) | 300 | ruby-debug-base (~> 0.10.4.0) |
@@ -327,7 +329,7 @@ GEM | @@ -327,7 +329,7 @@ GEM | ||
327 | daemons (>= 1.0.9) | 329 | daemons (>= 1.0.9) |
328 | eventmachine (>= 0.12.6) | 330 | eventmachine (>= 0.12.6) |
329 | rack (>= 1.0.0) | 331 | rack (>= 1.0.0) |
330 | - thor (0.17.0) | 332 | + thor (0.18.1) |
331 | timecop (0.3.5) | 333 | timecop (0.3.5) |
332 | treetop (1.4.12) | 334 | treetop (1.4.12) |
333 | polyglot | 335 | polyglot |
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +require 'problem_destroy' | ||
2 | + | ||
3 | +class ResolvedProblemClearer | ||
4 | + | ||
5 | + ## | ||
6 | + # Clear all problem already resolved | ||
7 | + # | ||
8 | + def execute | ||
9 | + nb_problem_resolved.tap { |nb| | ||
10 | + if nb > 0 | ||
11 | + criteria.each do |problem| | ||
12 | + ProblemDestroy.new(problem).execute | ||
13 | + end | ||
14 | + repair_database | ||
15 | + end | ||
16 | + } | ||
17 | + end | ||
18 | + | ||
19 | + private | ||
20 | + | ||
21 | + def nb_problem_resolved | ||
22 | + @count ||= criteria.count | ||
23 | + end | ||
24 | + | ||
25 | + def criteria | ||
26 | + @criteria = Problem.resolved | ||
27 | + end | ||
28 | + | ||
29 | + def repair_database | ||
30 | + Mongoid.config.master.command(:repairDatabase => 1) | ||
31 | + end | ||
32 | +end |
lib/tasks/errbit/database.rake
@@ -19,9 +19,8 @@ namespace :errbit do | @@ -19,9 +19,8 @@ namespace :errbit do | ||
19 | 19 | ||
20 | desc "Delete resolved errors from the database. (Useful for limited heroku databases)" | 20 | desc "Delete resolved errors from the database. (Useful for limited heroku databases)" |
21 | task :clear_resolved => :environment do | 21 | task :clear_resolved => :environment do |
22 | - count = Problem.resolved.count | ||
23 | - Problem.resolved.each {|problem| problem.destroy } | ||
24 | - puts "=== Cleared #{count} resolved errors from the database." if count > 0 | 22 | + require 'resolved_problem_clearer' |
23 | + puts "=== Cleared #{ResolvedProblemClearer.new.execute} resolved errors from the database." | ||
25 | end | 24 | end |
26 | 25 | ||
27 | desc "Regenerate fingerprints" | 26 | desc "Regenerate fingerprints" |
@@ -0,0 +1,52 @@ | @@ -0,0 +1,52 @@ | ||
1 | +require 'spec_helper' | ||
2 | + | ||
3 | +describe ResolvedProblemClearer do | ||
4 | + let(:resolved_problem_clearer) { | ||
5 | + ResolvedProblemClearer.new | ||
6 | + } | ||
7 | + describe "#execute" do | ||
8 | + let!(:problems) { | ||
9 | + [ | ||
10 | + Fabricate(:problem), | ||
11 | + Fabricate(:problem), | ||
12 | + Fabricate(:problem) | ||
13 | + ] | ||
14 | + } | ||
15 | + context 'without problem resolved' do | ||
16 | + it 'do nothing' do | ||
17 | + expect { | ||
18 | + expect(resolved_problem_clearer.execute).to eq 0 | ||
19 | + }.to_not change { | ||
20 | + Problem.count | ||
21 | + } | ||
22 | + end | ||
23 | + it 'not repair database' do | ||
24 | + Mongoid.config.master.should_receive(:command).and_call_original | ||
25 | + Mongoid.config.master.should_not_receive(:command).with({:repairDatabase => 1}) | ||
26 | + resolved_problem_clearer.execute | ||
27 | + end | ||
28 | + end | ||
29 | + | ||
30 | + context "with problem resolve" do | ||
31 | + before do | ||
32 | + problems.first.resolve! | ||
33 | + problems.second.resolve! | ||
34 | + end | ||
35 | + it 'delete problem resolve' do | ||
36 | + expect { | ||
37 | + expect(resolved_problem_clearer.execute).to eq 2 | ||
38 | + }.to change { | ||
39 | + Problem.count | ||
40 | + }.by(-2) | ||
41 | + expect(Problem.where(:_id => problems.first.id).first).to be_nil | ||
42 | + expect(Problem.where(:_id => problems.second.id).first).to be_nil | ||
43 | + end | ||
44 | + | ||
45 | + it 'repair database' do | ||
46 | + Mongoid.config.master.should_receive(:command).and_call_original | ||
47 | + Mongoid.config.master.should_receive(:command).with({:repairDatabase => 1}) | ||
48 | + resolved_problem_clearer.execute | ||
49 | + end | ||
50 | + end | ||
51 | + end | ||
52 | +end |