[Discord] Add daily janitor reports (#531)

* Add daily janitor reports

* More specific config name, improve formatting

---------

Co-authored-by: Earlopain <earlopain@protonmail.com>
This commit is contained in:
Donovan Daniels 2023-06-26 14:10:28 -05:00 committed by GitHub
parent eb7033dbc2
commit 55998374f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,49 @@
class JanitorReportGenerator
extend ActiveSupport::NumberHelper
def self.run!
return if Danbooru.config.janitor_reports_discord_webhook_url.blank?
current_stats = stats
previous_queue_size = Cache.redis.get("janitor_reports:previous_queue_size") || current_stats[:queue_size]
Cache.redis.set("janitor_reports:previous_queue_size", current_stats[:queue_size])
diff = current_stats[:queue_size] - previous_queue_size.to_i
content = <<~REPORT.chomp
Janitor report for <t:#{Time.now.to_i}:D>
Currently, there are #{number_to_delimited(current_stats[:queue_size])} pending posts. There were #{number_to_delimited(previous_queue_size)} pending posts yesterday.
That is #{number_to_delimited(diff)} #{diff >= 0 ? 'more' : 'less'} than the day before.
#{number_to_delimited(current_stats[:posts])} posts were added yesterday.
#{number_to_delimited(current_stats[:approvals] + current_stats[:deletions][:total])} posts were processed.
Approvals: #{number_to_delimited(current_stats[:approvals])}
Deletions: #{number_to_delimited(current_stats[:deletions][:total])} (#{number_to_delimited(current_stats[:deletions][:automod] - current_stats[:deletions][:takedowns])} automated, #{number_to_delimited(current_stats[:deletions][:takedowns])} takedown, #{number_to_delimited(current_stats[:deletions][:total] - current_stats[:deletions][:automod])} manual)
REPORT
HTTParty.post(
Danbooru.config.janitor_reports_discord_webhook_url,
body: {
content: content,
flags: 4096,
}.to_json,
headers: {
"Content-Type" => "application/json",
},
)
end
def self.stats
deletions = PostFlag.where(is_deletion: true).where("created_at >= ?", 1.day.ago)
{
queue_size: Post.pending.count,
deletions: {
total: deletions.count,
automod: deletions.where(creator_id: User.system.id).count,
takedowns: deletions.where("reason LIKE ?", "takedown #%").count,
},
approvals: PostApproval.where("created_at >= ?", 1.day.ago).count,
posts: Post.where("created_at >= ? ", 1.day.ago).count,
}
end
end

View File

@ -12,6 +12,7 @@ module Maintenance
ignoring_exceptions { Ban.prune! }
ignoring_exceptions { UserPasswordResetNonce.prune! }
ignoring_exceptions { StatsUpdater.run! }
ignoring_exceptions { JanitorReportGenerator.run! }
end
def ignoring_exceptions(&block)

View File

@ -768,6 +768,10 @@ module Danbooru
def enable_visitor_metrics?
false
end
def janitor_reports_discord_webhook_url
nil
end
end
class EnvironmentConfiguration