I have a function:
def self.run_all_scheduled_reports
scheduled_queries = Reports.find(
:all,
:joins=> 'INNER JOIN `expected_times`
ON (`reports`.`report_id` =`expected_times`.`report_id`)')
if scheduled_queries.empty?
print "No reports to run at this time ("+Time.now.to_s+")"
else
caught_exception = false
ActiveRecord::Base.connection.execute("SET SESSION WAIT_TIMEOUT=2400");
scheduled_queries.each do |query|
begin
print "Running report ("+query[:id].to_s+")...\n"
self.run_report(query[:id])
rescue Exception => e
caught_exception = true
print e
end
end
raise "At least one query resulted in an Exception!" if caught_exception
end
end
The weird thing is that, when i run this function consecutively (via script/runner -e ...), the result varies. Sometimes about 30 reports are printed while sometimes just 15 (and sometimes, no results at all are returned). You guys have any idea whats happening? My DB is MYSQL.
Also, if i change the environment to "development" OR if i omit the JOIN part, its working pretty well.
I just solved the issue, the inconsistency happens because apparently, my rails is set to use a separate layer/framework to do the db transactions. This middle layer randomly reads from 2 seperate MYSQL boxes, which turned out to be out of sync. Once i synced the 2 boxes, the problem was fixed. Thanks for all the help
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.