2019-05-03 08:17:27 +10:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-04-05 15:29:46 +11:00
|
|
|
module Jobs
|
2013-05-08 15:20:38 +10:00
|
|
|
# various consistency checks
|
2019-10-02 14:01:53 +10:00
|
|
|
class EnsureDbConsistency < ::Jobs::Scheduled
|
2014-02-11 16:11:40 +11:00
|
|
|
every 12.hours
|
2013-08-07 19:25:05 +02:00
|
|
|
|
2013-04-05 15:29:46 +11:00
|
|
|
def execute(args)
|
2025-02-13 12:07:04 +02:00
|
|
|
@measure_times = []
|
2019-08-29 13:27:04 +10:00
|
|
|
|
2024-12-22 21:33:47 +11:00
|
|
|
# we don't want to have a situation where Jobs::Badge or stuff like that is attempted to be run
|
|
|
|
# so we always prefix with :: to ensure we are running models
|
|
|
|
|
2019-08-29 13:27:04 +10:00
|
|
|
[
|
2024-12-22 21:33:47 +11:00
|
|
|
::UserVisit,
|
|
|
|
::Group,
|
|
|
|
::Notification,
|
|
|
|
::TopicFeaturedUsers,
|
|
|
|
::PostRevision,
|
|
|
|
::Topic,
|
|
|
|
::Badge,
|
|
|
|
::CategoryUser,
|
|
|
|
::UserOption,
|
|
|
|
::Tag,
|
|
|
|
::CategoryTagStat,
|
|
|
|
::User,
|
|
|
|
::UserAvatar,
|
|
|
|
::UserEmail,
|
|
|
|
::Category,
|
|
|
|
::TopicThumbnail,
|
2025-02-13 12:07:04 +02:00
|
|
|
::UserAction,
|
|
|
|
::UserStat,
|
|
|
|
::GroupUser,
|
2019-08-29 13:27:04 +10:00
|
|
|
].each do |klass|
|
2025-02-13 12:07:04 +02:00
|
|
|
measure_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
|
|
|
|
|
|
begin
|
|
|
|
if [::UserAction, ::UserStat, ::GroupUser].include?(klass)
|
|
|
|
klass.ensure_consistency!(13.hours.ago)
|
|
|
|
else
|
|
|
|
klass.ensure_consistency!
|
|
|
|
end
|
|
|
|
rescue StandardError => e
|
|
|
|
Rails.logger.error("Error ensuring consistency for #{klass}: #{e.message}")
|
|
|
|
end
|
|
|
|
|
|
|
|
@measure_times << [klass, Process.clock_gettime(Process::CLOCK_MONOTONIC) - measure_start]
|
2019-08-29 13:27:04 +10:00
|
|
|
end
|
|
|
|
|
|
|
|
Rails.logger.debug(format_measure)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def format_measure
|
2020-10-07 22:51:04 +02:00
|
|
|
result = +"EnsureDbConsistency Times\n"
|
2019-08-29 13:27:04 +10:00
|
|
|
result << @measure_times.map { |name, duration| " #{name}: #{duration}" }.join("\n")
|
|
|
|
result
|
|
|
|
end
|
2013-04-05 15:29:46 +11:00
|
|
|
end
|
|
|
|
end
|