From e6a4ec56237f97bccf7a7a502717d5a8a9308f73 Mon Sep 17 00:00:00 2001 From: saint Date: Mon, 19 Aug 2024 18:26:02 +1000 Subject: [PATCH] v0.49 Work on MySQL brokenness --- gossamer_forums.rb | 58 ++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 33 deletions(-) diff --git a/gossamer_forums.rb b/gossamer_forums.rb index 9abf6f2..c763455 100644 --- a/gossamer_forums.rb +++ b/gossamer_forums.rb @@ -1156,33 +1156,32 @@ class GossamerForumsImporter < ImportScripts::Base # Submit the import job for the current post_id to the thread pool 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}" 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 puts "PP 11 -- #{post_id} -- Checking MySQL connections status.." - mysql_client.ping -## || mysql_client = Mysql2::Client.new( -## host: "slowtwitch.northend.network", -## username: "admin", -## password: "yxnh93Ybbz2Nm8#mp28zCVv", -## database: "slowtwitch" -## ) -#### puts " FIRST Checking MySQL connection status..." -#### if mysql_client.query('SELECT 1').nil? -#### puts " MySQL connection is not valid" -#### else -#### puts " MySQL connection is valid" -#### end + mysql_client.ping || mysql_client = Mysql2::Client.new( + host: "slowtwitch.northend.network", + username: "admin", + password: "yxnh93Ybbz2Nm8#mp28zCVv", + database: "slowtwitch" + ) + puts " FIRST Checking MySQL connection status..." + if mysql_client.query('SELECT 1').nil? + puts " !! MySQL connection is NOT VALID !!" + else + puts " MySQL connection is valid" + end # Use connection pooling for PostgreSQL and synchronize access to shared resources ActiveRecord::Base.connection_pool.with_connection do @@ -1197,7 +1196,7 @@ class GossamerForumsImporter < ImportScripts::Base puts "Skipping post_id #{post_id}, already processed." end end - end +####### end rescue => e puts "Error processing post ID #{post_id}: #{e.message}" 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..." retry end -#### ensure -#### # Ensure the MariaDB connection is closed after processing -#### mysql_client.close if mysql_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 + ensure + # Ensure the MariaDB connection is closed after processing + mysql_client.close if mysql_client + puts "** CLOSED MariaDB client" end end end