DEV: Rescue from each step of EnsureDbConsistency (#31313)

A failure early in the job would prevent the rest of the ensure
consistency methods to run.
This commit is contained in:
Bianca Nenciu 2025-02-13 12:07:04 +02:00 committed by GitHub
parent cbe9a9f33b
commit 2b996a9d39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ module Jobs
every 12.hours
def execute(args)
start_measure
@measure_times = []
# 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
@ -28,19 +28,24 @@ module Jobs
::UserEmail,
::Category,
::TopicThumbnail,
::UserAction,
::UserStat,
::GroupUser,
].each do |klass|
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!
measure(klass)
end
rescue StandardError => e
Rails.logger.error("Error ensuring consistency for #{klass}: #{e.message}")
end
UserAction.ensure_consistency!(13.hours.ago)
measure(UserAction)
UserStat.ensure_consistency!(13.hours.ago)
measure(UserStat)
GroupUser.ensure_consistency!(13.hours.ago)
measure(GroupUser)
@measure_times << [klass, Process.clock_gettime(Process::CLOCK_MONOTONIC) - measure_start]
end
Rails.logger.debug(format_measure)
nil
@ -53,16 +58,5 @@ module Jobs
result << @measure_times.map { |name, duration| " #{name}: #{duration}" }.join("\n")
result
end
def start_measure
@measure_times = []
@measure_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
end
def measure(step = nil)
@measure_now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
@measure_times << [step, @measure_now - @measure_start] if @measure_start
@measure_start = @measure_now
end
end
end