maintenance: break maintenance tasks into individual jobs.
Break the hourly/daily/weekly/monthly maintenance tasks down into individual delayed jobs. This way if one task fails, it won't prevent other tasks from running. Also, jobs can be run in parallel, and can be individually retried if they fail.
This commit is contained in:
@@ -3,38 +3,36 @@ require 'test_helper'
|
||||
class DanbooruMaintenanceTest < ActiveSupport::TestCase
|
||||
context "hourly maintenance" do
|
||||
should "work" do
|
||||
assert_nothing_raised { DanbooruMaintenance.hourly }
|
||||
end
|
||||
|
||||
should "prune expired posts" do
|
||||
@pending = create(:post, is_pending: true, created_at: 5.days.ago)
|
||||
@flagged = create(:post, is_flagged: true, created_at: 5.days.ago)
|
||||
@appealed = create(:post, is_deleted: true, created_at: 5.days.ago)
|
||||
|
||||
@flag = create(:post_flag, post: @flagged, created_at: 4.days.ago)
|
||||
@appeal = create(:post_appeal, post: @appealed, created_at: 4.days.ago)
|
||||
|
||||
DanbooruMaintenance.hourly
|
||||
|
||||
assert_equal(true, @pending.reload.is_deleted?)
|
||||
assert_equal(true, @flagged.reload.is_deleted?)
|
||||
assert_equal(true, @appealed.reload.is_deleted?)
|
||||
assert_equal(true, @flag.reload.succeeded?)
|
||||
assert_equal(true, @appeal.reload.rejected?)
|
||||
assert_nothing_raised do
|
||||
DanbooruMaintenance.hourly
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "hourly maintenance" do
|
||||
context "when pruning bans" do
|
||||
should "clear the is_banned flag for users who are no longer banned" do
|
||||
banner = FactoryBot.create(:admin_user)
|
||||
user = FactoryBot.create(:user)
|
||||
context "daily maintenance" do
|
||||
should "work" do
|
||||
assert_nothing_raised do
|
||||
DanbooruMaintenance.daily
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
as(banner) { create(:ban, user: user, banner: banner, duration: 1) }
|
||||
context "weekly maintenance" do
|
||||
should "work" do
|
||||
assert_nothing_raised do
|
||||
DanbooruMaintenance.weekly
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert_equal(true, user.reload.is_banned)
|
||||
travel_to(2.days.from_now) { DanbooruMaintenance.daily }
|
||||
assert_equal(false, user.reload.is_banned)
|
||||
context "monthly maintenance" do
|
||||
should "work" do
|
||||
assert_nothing_raised do
|
||||
DanbooruMaintenance.monthly
|
||||
perform_enqueued_jobs
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -194,19 +194,4 @@ class TagTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "A tag with an incorrect post count" do
|
||||
should "be fixed" do
|
||||
tag1 = FactoryBot.create(:tag, name: "touhou", post_count: -10)
|
||||
tag2 = FactoryBot.create(:tag, name: "bkub", post_count: 10)
|
||||
tag3 = FactoryBot.create(:tag, name: "chen", post_count: 10)
|
||||
post = FactoryBot.create(:post, tag_string: "touhou bkub")
|
||||
|
||||
tags = Tag.regenerate_post_counts!
|
||||
assert_equal(3, tags.size)
|
||||
assert_equal(1, tag1.reload.post_count)
|
||||
assert_equal(1, tag2.reload.post_count)
|
||||
assert_equal(0, tag3.reload.post_count)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user