Wnt2bsleepin
Wnt2bsleepin

Reputation: 59

SQLite3 BusyException during update

I am having a hard time updating information in a database. Originally, when I try to save the changes, it gives me the error that the database is locked.

SQLite3::BusyException: cannot rollback transaction - SQL statements in progress: rollback transaction

Here is the daemon in question:

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

I am only using the sqlite to store some information, the other database is a MySQL database which is only being read from. Any help is much appreciated.

Upvotes: 0

Views: 390

Answers (1)

jxpx777
jxpx777

Reputation: 3641

This sounds like an issue I had with a project recently. SQLite was working great in development and beta testing, but under the strain of production environment, the whole thing broke down. I'm converting the project to a different architecture (Resque) and so far performance is better and I plan to deploy the new architecture next week. At a minimum, you should convert to MySQL to avoid these errors.

Upvotes: 1

Related Questions