maintenance: consolidate maintenance tasks in logical/maintenance.rb.

This commit is contained in:
evazion
2018-10-07 22:22:45 -05:00
parent 1a4949368c
commit 5201954413
5 changed files with 23 additions and 31 deletions

View File

@@ -1,5 +1,12 @@
class DailyMaintenance
def run
module Maintenance
module_function
def hourly
UploadErrorChecker.new.check!
DelayedJobErrorChecker.new.check!
end
def daily
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
PostPruner.new.prune!
Upload.where('created_at < ?', 1.day.ago).delete_all
@@ -18,4 +25,11 @@ class DailyMaintenance
TagChangeRequestPruner.reject_all
Ban.prune!
end
def weekly
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
UserPasswordResetNonce.prune!
ApproverPruner.prune!
TagRelationshipRetirementService.find_and_retire!
end
end

View File

@@ -1,5 +0,0 @@
class MonthlyMaintenance
def run
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
end
end

View File

@@ -1,8 +0,0 @@
class WeeklyMaintenance
def run
ActiveRecord::Base.connection.execute("set statement_timeout = 0")
UserPasswordResetNonce.prune!
ApproverPruner.prune!
# JanitorPruner.new.prune!
end
end

View File

@@ -2,15 +2,11 @@ set :output, "/var/log/whenever.log"
#env "MAILTO", "webmaster@danbooru.donmai.us"
every 1.hour do
runner "UploadErrorChecker.new.check!"
end
every 1.hour do
runner "DelayedJobErrorChecker.new.check!"
runner "Maintenance.hourly"
end
every 1.day do
runner "DailyMaintenance.new.run"
runner "Maintenance.daily"
end
every 1.day, :at => "1:00 am" do
@@ -18,10 +14,5 @@ every 1.day, :at => "1:00 am" do
end
every 1.week, :at => "1:30 am" do
runner "WeeklyMaintenance.new.run"
runner "TagRelationshipRetirementService.find_and_retire!"
end
every 1.month, :at => "2:00 am" do
runner "MonthlyMaintenance.new.run"
runner "Maintenance.weekly"
end

View File

@@ -1,6 +1,6 @@
require 'test_helper'
class DailyMaintenanceTest < ActiveSupport::TestCase
class MaintenanceTest < ActiveSupport::TestCase
context "daily maintenance" do
setup do
# have ApiCacheGenerator save files to a temp dir.
@@ -17,14 +17,14 @@ class DailyMaintenanceTest < ActiveSupport::TestCase
end
should "work" do
assert_nothing_raised { DailyMaintenance.new.run }
assert_nothing_raised { Maintenance.daily }
end
should "prune expired posts" do
@pending = FactoryBot.create(:post, is_pending: true, created_at: 4.days.ago)
@flagged = FactoryBot.create(:post, is_flagged: true, created_at: 4.days.ago)
DailyMaintenance.new.run
Maintenance.daily
assert(true, @pending.reload.is_deleted)
assert(true, @flagged.reload.is_deleted)
@@ -38,7 +38,7 @@ class DailyMaintenanceTest < ActiveSupport::TestCase
CurrentUser.as(banner) { FactoryBot.create(:ban, user: user, banner: banner, duration: 1) }
assert_equal(true, user.reload.is_banned)
travel_to(2.days.from_now) { DailyMaintenance.new.run }
travel_to(2.days.from_now) { Maintenance.daily }
assert_equal(false, user.reload.is_banned)
end
end