Skip to content

Commit

Permalink
outdated error clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
deathowl committed Jan 8, 2014
1 parent bf93f2f commit d7a4f5c
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions app/interactors/outdated_prolem_clearer.rb
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

0 comments on commit d7a4f5c

Please sign in to comment.