set timeout on certain rails controller action

user3576036 Source

I have quiz app where there are multiple questions with options to select.

The controller actions are as follows


#the questions appear on `new` page

 def new
    @quiz = Quiz.find(params[:quiz_id])
    @reply =
    @quiz.questions.each {|question| question)}

#once user submits the answers it goes to create

  def create
    @quiz = Quiz.find(params[:quiz_id])
    @reply = reply_params
      redirect_to @quiz, notice: "Thank you for taking the quiz"

What I am trying to achieve is , after like 30 minutes it should automatically create. If creating empty params is a bad idea then at-least there should be way to show a message or redirect to root page after 30 minutes. How can I achieve this ?



answered 6 months ago Ryan Clark #1

I think your best bet is going to be to use something like Sidekiq to delay the creation of a reply. You can create an empty one and send the id, along with the params to a worker and delay the rest of the work for a set period of time, like 30 minutes. You'll need a worker, something like a ReplyCreationWorker to call in the controller, then you can redirect with a message to check back in 30 minutes.

comments powered by Disqus