2
votes

ActiveRecord::StatementInvalid: SQLite3::SQLException: cannot rollback - no transaction is active: rollback transaction

I have tried to save a large amount of data in heroku but I couldn't do that because of the response time limit of 30 seconds so I decided to use delayed_job. However, since I have never used delayed_job so I don't know how to solve the following error

Error

NoMethodError (undefined method `quizlet_save' for Word(id: integer, group_id: integer, user_id: integer, answer: string, question: string, title: string, image: string, created_at: datetime, updated_at: datetime, answer_language: string, question_language: string, favorites_count: integer, quizlet_id: integer, check_id: string)):

code

   def index
@words = params[:tag].present?? Word.tagged_with(params[:tag]) : Word.all
@words [email protected](:tags)
@groups=Group.all
@[email protected](params[:q])
@search_result = @search.result #この行を修正
@search_result = @search_result.uniq
respond_to do |format|
  format.html
  format.json { render json: @search_result}
end
quizlet

end

  def quizlet
      @response=[]
               response = Unirest.get "https://api.quizlet.com/2.0/search/sets/?client_id=7JH38T27zM&whitespace=1",
                       parameters:{ whitespace: true,q: "Duo3.0",term:100,sort:"most_studied"}
      res=response.body

      quizlet_ids=[]
        res["sets"].each do|res|
           quizlet_ids<<res["id"]
       end


      quizlet_words = Unirest.get "https://api.quizlet.com/2.0/sets/?client_id=7JH38T27zM&whitespace=1",
                            parameters:{ whitespace: true,set_ids:"#{quizlet_ids}"}

   quizlet_words.body.each do|words|
     words["terms"].each do|word|
      response=word
    response["quizlet_id"]=words["id"]
    response["check_id"]=word["id"]
    response["question_language"]= words["lang_terms"]
    response["answer_language"]  = words["lang_definitions"]
    @response<<response
    @response.each do|response|
      response
      Word.delay.quizlet_save(response["quizlet_id"],response["check_id"],response["term"],response["definition"],response["question_language"],response["answer_language"])
    end
  end
end

end

model

def quizlet_save(quizlet_id,check_id,question,answer,question_language,answer_language)
     unless Word.find_by(check_id:check_id)&&Word.find_by(quizlet_id:quizlet_id)
     Word.create(quizlet_id:quizlet_id,check_id:check_id,title:"Quizlet",question:question,answer:answer,user_id:1,tag_list:"English,duo3.0,Vocabulary",
              question_language:question_language,answer_language:answer_language)
    end
 end

  def quizlet_create_groups(quizlet_id,check_id)
   word=Word.find_by(check_id:check_id)
   unless word == nil
    checking_word=Word.find_by(quizlet_id:quizlet_id)
    group=Group.find_by(id: checking_word.group_id)
    if group==nil
       created_group=Group.new(user_id:1,title:"Quizlet",explanation:"Quizlet Duo3.0")
       created_group=created_group.save(validate: false)&&created_group
       word.update_attribute(:group_id,created_group.id)
     else
    word.update_attribute(:group_id,group.id)
    end
   end
 end

environment

  • ruby 2.3.1
  • ruby on rails 4.2.7
  • delayed_job_active_record (4.1.2)
1
quizlet_save can be called only for model objects and response is not a model object.Sajin
It needs too much time to save many datas so I should save nil object first, then update?Ryu Nishida
What is the model name?Sajin
That is Word model.Ryu Nishida
Then try Word.new.delay.quizlet_save(response["quizlet_id"],response["check_id"],response["term"],response["definition"],response["question_language"],response["answer_language"])Sajin

1 Answers

1
votes

I could find the solution at delayed_job's Github issue.The person who is owner of delayed_job's repository said me that you can't use any Asynchronous gems except sucker_punch in SQLite.Thank you for answering.