-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
deathowl
committed
Jan 8, 2014
1 parent
bf93f2f
commit d7a4f5c
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'problem_destroy' | ||
|
||
class OutdatedProblemClearer | ||
|
||
## | ||
# Clear all problem not present for more than one week. | ||
# | ||
def execute | ||
nb_problem_outdated.tap { |nb| | ||
if nb > 0 | ||
criteria.each do |problem| | ||
ProblemDestroy.new(problem).execute | ||
end | ||
repair_database | ||
end | ||
} | ||
end | ||
|
||
private | ||
|
||
def nb_problem_outdated | ||
@count ||= criteria.count | ||
end | ||
|
||
def criteria | ||
@criteria = (Time.new - Problem.last_notice_at) / 3600 / 24 > 7 | ||
end | ||
|
||
def repair_database | ||
Mongoid.default_session.command :repairDatabase => 1 | ||
end | ||
end |