0

我很难更新数据库中的信息。最初,当我尝试保存更改时,它给了我数据库被锁定的错误。

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 数据库,它只是被读取。任何帮助深表感谢。

4

1 回答 1

1

这听起来像是我最近在一个项目中遇到的问题。SQLite 在开发和 beta 测试中表现出色,但在生产环境的压力下,整个事情都崩溃了。我正在将项目转换为不同的架构(Resque),到目前为止性能更好,我计划下周部署新架构。至少,您应该转换为 MySQL 以避免这些错误。

于 2012-12-30T23:53:00.877 回答