maintenance: prevent exceptions from halting daily maintenance.

Fix cases where not all daily maintenance tasks run because some earlier
task raised an exception.
This commit is contained in:
evazion
2019-12-28 00:19:52 -06:00
parent 56d787a17f
commit c95108d37b

View File

@@ -5,33 +5,26 @@ module DanbooruMaintenance
end end
def daily def daily
ActiveRecord::Base.connection.execute("set statement_timeout = 0") safely { PostPruner.new.prune! }
PostPruner.new.prune! safely { Upload.prune! }
Upload.prune! safely { Delayed::Job.where('created_at < ?', 45.days.ago).delete_all }
Delayed::Job.where('created_at < ?', 45.days.ago).delete_all safely { PostDisapproval.prune! }
PostDisapproval.prune! safely { ForumSubscription.process_all! }
ForumSubscription.process_all! safely { PostDisapproval.dmail_messages! }
PostDisapproval.dmail_messages! safely { regenerate_post_counts! }
regenerate_post_counts! safely { SuperVoter.init! }
SuperVoter.init! safely { TokenBucket.prune! }
TokenBucket.prune! safely { TagChangeRequestPruner.warn_all }
TagChangeRequestPruner.warn_all safely { TagChangeRequestPruner.reject_all }
TagChangeRequestPruner.reject_all safely { Ban.prune! }
Ban.prune! safely { CuratedPoolUpdater.update_pool! }
CuratedPoolUpdater.update_pool! safely { ActiveRecord::Base.connection.execute("vacuum analyze") unless Rails.env.test? }
ActiveRecord::Base.connection.execute("vacuum analyze") unless Rails.env.test?
rescue Exception => exception
rescue_exception(exception)
end end
def weekly def weekly
ActiveRecord::Base.connection.execute("set statement_timeout = 0") safely { UserPasswordResetNonce.prune! }
UserPasswordResetNonce.prune! safely { ApproverPruner.prune! }
ApproverPruner.prune! safely { TagRelationshipRetirementService.find_and_retire! }
TagRelationshipRetirementService.find_and_retire!
rescue Exception => exception
rescue_exception(exception)
end end
def regenerate_post_counts! def regenerate_post_counts!
@@ -41,8 +34,10 @@ module DanbooruMaintenance
end end
end end
def rescue_exception(exception) def safely(&block)
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
yield
rescue StandardError => exception
DanbooruLogger.log(exception) DanbooruLogger.log(exception)
raise exception
end end
end end