class Maintenance::BackfillSnipScoresJob < ApplicationJob
queue_as :maintenance
def perform
ActiveRecord::Base.connection_pool.with_connection do |conn|
conn.verify!
Snip.find_each(batch_size: 1000) do |snip|
Snip.where(id: snip.id).update_all(score: snip.views)
end
end
end
end
Long-running jobs can hit stale connections. Wrap work in with_connection and consider verify! before heavy DB usage. This reduces “PG::ConnectionBad” noise during long maintenance tasks.