mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
parent
cbe9a9f33b
commit
2b996a9d39
@ -6,7 +6,7 @@ module Jobs
|
|||||||
every 12.hours
|
every 12.hours
|
||||||
|
|
||||||
def execute(args)
|
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
|
# 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
|
# so we always prefix with :: to ensure we are running models
|
||||||
@ -28,20 +28,25 @@ module Jobs
|
|||||||
::UserEmail,
|
::UserEmail,
|
||||||
::Category,
|
::Category,
|
||||||
::TopicThumbnail,
|
::TopicThumbnail,
|
||||||
|
::UserAction,
|
||||||
|
::UserStat,
|
||||||
|
::GroupUser,
|
||||||
].each do |klass|
|
].each do |klass|
|
||||||
klass.ensure_consistency!
|
measure_start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
||||||
measure(klass)
|
|
||||||
|
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]
|
||||||
end
|
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)
|
|
||||||
|
|
||||||
Rails.logger.debug(format_measure)
|
Rails.logger.debug(format_measure)
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
@ -53,16 +58,5 @@ module Jobs
|
|||||||
result << @measure_times.map { |name, duration| " #{name}: #{duration}" }.join("\n")
|
result << @measure_times.map { |name, duration| " #{name}: #{duration}" }.join("\n")
|
||||||
result
|
result
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user