v0.49 Work on MySQL brokenness

This commit is contained in:
David Sainty 2024-08-19 18:26:02 +10:00
parent cdd512bf06
commit e6a4ec5623

View File

@ -1156,33 +1156,32 @@ class GossamerForumsImporter < ImportScripts::Base
# Submit the import job for the current post_id to the thread pool # Submit the import job for the current post_id to the thread pool
pool.post do pool.post do
# Initialise a new MariaDB / Mysql2 client inside of each thread
#### mysql_client = Mysql2::Client.new(
#### host: "slowtwitch.northend.network",
#### username: "admin",
#### password: "yxnh93Ybbz2Nm8#mp28zCVv",
#### database: "slowtwitch"
#### )
#### puts "PP 22 -- #{post_id}" #### puts "PP 22 -- #{post_id}"
begin begin
mariadb_pool.with do |mysql_client| ####### mariadb_pool.with do |mysql_client|
# Initialise a new MariaDB / Mysql2 client inside of each thread
mysql_client = Mysql2::Client.new(
host: "slowtwitch.northend.network",
username: "admin",
password: "yxnh93Ybbz2Nm8#mp28zCVv",
database: "slowtwitch"
)
# Ensure the connection is active, otherwise reconnect # Ensure the connection is active, otherwise reconnect
puts "PP 11 -- #{post_id} -- Checking MySQL connections status.." puts "PP 11 -- #{post_id} -- Checking MySQL connections status.."
mysql_client.ping mysql_client.ping || mysql_client = Mysql2::Client.new(
## || mysql_client = Mysql2::Client.new( host: "slowtwitch.northend.network",
## host: "slowtwitch.northend.network", username: "admin",
## username: "admin", password: "yxnh93Ybbz2Nm8#mp28zCVv",
## password: "yxnh93Ybbz2Nm8#mp28zCVv", database: "slowtwitch"
## database: "slowtwitch" )
## ) puts " FIRST Checking MySQL connection status..."
#### puts " FIRST Checking MySQL connection status..." if mysql_client.query('SELECT 1').nil?
#### if mysql_client.query('SELECT 1').nil? puts " !! MySQL connection is NOT VALID !!"
#### puts " MySQL connection is not valid" else
#### else puts " MySQL connection is valid"
#### puts " MySQL connection is valid" end
#### end
# Use connection pooling for PostgreSQL and synchronize access to shared resources # Use connection pooling for PostgreSQL and synchronize access to shared resources
ActiveRecord::Base.connection_pool.with_connection do ActiveRecord::Base.connection_pool.with_connection do
@ -1197,7 +1196,7 @@ class GossamerForumsImporter < ImportScripts::Base
puts "Skipping post_id #{post_id}, already processed." puts "Skipping post_id #{post_id}, already processed."
end end
end end
end ####### end
rescue => e rescue => e
puts "Error processing post ID #{post_id}: #{e.message}" puts "Error processing post ID #{post_id}: #{e.message}"
puts e.backtrace.join("\n") # Print the full stack trace puts e.backtrace.join("\n") # Print the full stack trace
@ -1209,17 +1208,10 @@ class GossamerForumsImporter < ImportScripts::Base
puts "Reconnecting to MySQL for post ID #{post_id} due to connection loss..." puts "Reconnecting to MySQL for post ID #{post_id} due to connection loss..."
retry retry
end end
#### ensure ensure
#### # Ensure the MariaDB connection is closed after processing # Ensure the MariaDB connection is closed after processing
#### mysql_client.close if mysql_client mysql_client.close if mysql_client
#### puts "** CLOSED MariaDB client" puts "** CLOSED MariaDB client"
#### puts "PP 22 -- #{post_id}"
#### puts " FINAL Checking MySQL connection status..."
#### if mysql_client.query('SELECT 1').nil?
#### puts " MySQL connection is not valid"
#### else
#### puts " MySQL connection is valid"
#### end
end end
end end
end end