0

ID의 CSV 파일을 통해 foreach하는 레이크 작업이 있습니다. 그런 다음 데이터베이스에 쿼리하여 해당 ID가 내 데이터베이스에 있는지 확인합니다. 그것이 존재한다면 저는 act_as_taggable을 사용하여 태그를 추가합니다. 스크립트는 첫 번째 일치 항목에 도달하고 SQLite DB에 태그를 쓰려고 시도 할 때까지 잘 실행됩니다. 나는 데이터베이스 잠김 오류가 발생합니다. 내가 SQLite의 I/O 한계를 맞추고 있으며 fullblown MySQL DB로 전환해야하는지 궁금합니다.Rake SQLite에서 CSV 작업의 태그를 많이 지정하고 있습니까?

if defined?(Rails) && (Rails.env == 'development') 
    Rails.logger = Logger.new(STDOUT) 
end 

require 'csv' 
desc "Tag Voters that early voted from the Secretary of State Website" 
task :tag_early => [:environment] do 
    file ="db/AllAbsentees.csv" 

    CSV.foreach(file, :headers=> true) do |row| 
    @voter_id = row[1] 
    puts "Working on Row" + row[1] 
    @voter = Voter.where(:state_id => @voter_id).first() 
    unless @voter.blank? 
     @voter.tag_list = "2012_GEN_EARLY_VOTER" 
     @voter.save() 
     puts "Voter #" + @voter_id + "tagged" 
    end 
    end 
end 


    Voter Load (1.2ms) SELECT "voters".* FROM "voters" WHERE "voters"."state_id" = '00008030' LIMIT 1 
    ActsAsTaggableOn::Tag Load (0.2ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 11944 AND "taggings"."taggable_type" = 'Voter' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) 
    (0.1ms) begin transaction 
    (0.4ms) UPDATE "voters" SET "updated_at" = '2012-11-23 00:02:33.438114' WHERE "voters"."id" = 11944 
    ActsAsTaggableOn::Tag Load (0.1ms) SELECT "tags".* FROM "tags" WHERE (lower(name) = '2012_gen_early_voter') 
    ActsAsTaggableOn::Tag Load (0.2ms) SELECT "tags".* FROM "tags" INNER JOIN "taggings" ON "tags"."id" = "taggings"."tag_id" WHERE "taggings"."taggable_id" = 11944 AND "taggings"."taggable_type" = 'Voter' AND (taggings.context = 'tags' AND taggings.tagger_id IS NULL) 
    ActsAsTaggableOn::Tagging Exists (0.1ms) SELECT 1 AS one FROM "taggings" WHERE ("taggings"."tag_id" = 19 AND "taggings"."taggable_type" = 'Voter' AND "taggings"."taggable_id" = 11944 AND "taggings"."context" = 'tags' AND "taggings"."tagger_id" IS NULL AND "taggings"."tagger_type" IS NULL) LIMIT 1 
    SQL (1.4ms) INSERT INTO "taggings" ("context", "created_at", "tag_id", "taggable_id", "taggable_type", "tagger_id", "tagger_type") VALUES (?, ?, ?, ?, ?, ?, ?) [["context", "tags"], ["created_at", Fri, 23 Nov 2012 00:02:33 UTC +00:00], ["tag_id", 19], ["taggable_id", 11944], ["taggable_type", "Voter"], ["tagger_id", nil], ["tagger_type", nil]] 
    (5053.1ms) commit transaction 
SQLite3::BusyException: database is locked: commit transaction 
    (99.7ms) rollback transaction 
rake aborted! 
SQLite3::BusyException: database is locked: commit transaction 

답변

1

SQLite의 동시성은 그리 높지 않습니다. 트랜잭션이 DB에 쓰려면 다른 읽기 또는 쓰기 연결이 없어야합니다.

동시에 다른 프로그램이 DB에서 읽거나 DB에 쓰는 것이없고 자신의 프로그램에있는 모든 DB 액세스가 동일한 데이터베이스 연결을 사용하는지 확인하십시오.

+0

어제 밤에 집에 돌아와서 MySQL을 설치했는데 정상적으로 작동했습니다. – gsueagle2008