我很难更新数据库中的信息。最初,当我尝试保存更改时,它会向我提供数据库被锁定的错误。
SQLite3::BusyException: cannot rollback transaction - SQL statements in progress: rollback transaction
这是有问题的守护进程:
require 'daemons'
require File.expand_path(
File.join(File.dirname(__FILE__), '..', 'config', 'environment'))
Daemons.run_proc('clock.rb')do
daemon_log = ActiveSupport::BufferedLogger.new(
File.join(Rails.root, "log", "clock.log"))
Rails.logger = ActiveRecord::Base.logger = daemon_log
Rails.logger = ActiveRecord::Base.logger.info("running clock.rb")
Rails.logger = ActiveRecord::Base.logger.info("Information Retrieved")
UserStats = UgloungeSkills.find(:all)
loop do
Rails.logger = ActiveRecord::Base.logger.info("running main loop")
UserStats.each do |row|
powerLevel = row['taming'] + row['mining'] + row['woodcutting'] + row['repair'] + row['unarmed'] + row['herbalism'] + row['excavation'] + row['archery'] + row['swords'] + row['axes'] + row['acrobatics'] + row['fishing']
userName = UgloungeUser.find(row['user_id'])['user']
McMMO_id = row['user_id']
if(User.exists?(name: userName))
#Update it
singleUser = User.find(McMMO_id)
Rails.logger = ActiveRecord::Base.logger.info("Just updating information")
Rails.logger = ActiveRecord::Base.logger.info("User: " + singleUser['name'])
#Rails.logger = ActiveRecord::Base.logger.info("Values of power_level and McMMO_id: " + powerLevel)
singleUser.name = "Poopyhead"
singleUser.save
#singleUser.update_attributes(power_level: powerLevel, mcmmo_id: McMMO_id)
Rails.logger = ActiveRecord::Base.logger.info("Finished updating")
else
#Create a new user
Rails.logger = ActiveRecord::Base.logger.info("Creating new user")
User.create(name: userName, power_level: powerLevel, mcmmo_id: McMMO_id)
end
end
sleep(120)
Rails.logger = ActiveRecord::Base.logger.info("Sleeping")
end
end
我只使用sqlite存储一些信息,另一个数据库是一个只读取的MySQL数据库。非常感谢任何帮助。
答案 0 :(得分:1)
这听起来像是我最近在项目中遇到的一个问题。 SQLite在开发和beta测试方面做得很好,但在生产环境的压力下,整个事情都崩溃了。我正在将项目转换为不同的架构(Resque),到目前为止性能更好,我打算下周部署新的架构。至少应该转换为MySQL以避免这些错误。