Files
danbooru/app/jobs/amcheck_database_job.rb
evazion 950bc608c2 maintenance: add job to check for database corruption.
Add a job to run pg_amcheck hourly to check for corrupt database indexes.

https://www.postgresql.org/docs/14/app-pgamcheck.html
2021-10-06 08:08:52 -05:00

19 lines
744 B
Ruby

# A job that runs hourly to check the database for corruption. Spawned by {DanbooruMaintenance}.
# Requires at least PostgreSQL 14.0 to be installed for pg_amcheck to be available.
#
# https://www.postgresql.org/docs/14/app-pgamcheck.html
class AmcheckDatabaseJob < ApplicationJob
def perform(options: "--verbose --install-missing --heapallindexed --parent-check")
return unless system("pg_amcheck --version")
connection_url = ApplicationRecord.connection_db_config.url
output = %x(PGDATABASE="#{connection_url}" pg_amcheck #{options})
notify(output) unless $?.success?
end
def notify(output)
DanbooruLogger.info(output)
Dmail.create_automated(to: User.owner, title: "pg_amcheck failed", body: output)
end
end