我很难更新数据库中的信息。最初,当我尝试保存更改时,它给了我数据库被锁定的错误。
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 数据库,它只是被读取。任何帮助深表感谢。