Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8571425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:46:44+00:00 2026-06-11T18:46:44+00:00

Suppose I have an User model and when I create a new user model,

  • 0

Suppose I have an User model and when I create a new user model, I spawn a new thread that needs to some networking/background tasks after the user has been created.

def create
  @user = User.new(params[:user])

  collect_info_async(@user)

  respond_to do |format|
    if @user.save
      format.html { redirect_to @user, notice: 'User created.' }
    else
      format.html { render action: "new" }
    end
  end
end


def collect_info_async(user)
  Thread.new do
    logger.info "Thread starting" #Gets logged correctly

    #Do some network requests, perform calculations, etc.

    usr = User.find_by_id(user.id).update_attributes(:info => gathered_info)
    logger.info "Thread finishing"


   end
end

When I create a new user, then in the logs I see “Thread starting”, but I don’t see “Thread finishing” at the same moment when it really finishes. I have to do a User.find from the console or refresh the user page after some time and then I am able to see the “Thread finishing” log. So when does the asynchronous task really finish? And is using a Thread the right choice? I’m using Ruby 1.9.3 and Rails 3.2.8.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:46:45+00:00Added an answer on June 11, 2026 at 6:46 pm

    At the moment is it better to use a dedicated worker process for background jobs in Rails, instead if using threads. You could use Sidekiq, Resque, delayed_job, etc. RailsCasts have some good screencasts about those.

    There is actually a good RailsCast about thread-safety. You need to be a pro member to watch it, however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following models: class User(models.Model): pass class A(models.Model): user = models.ForeignKey(User)
Suppose I have a user defined type: CREATE OR REPLACE TYPE TEST_TYPE AS OBJECT
Suppose we have a menu which presents the user with some options: Welcome: 1)
I have one simple app that suppose to get information from user and send
Suppose, I want to have a link or a button that when user click
Suppose I have an app that displays pictures of Pizzas. Let's say the model
Suppose you have two models, User and City, joined by a third model CityPermission:
Suppose I have a model user , which has a uniqueness constraint on the
Suppose I have a domain model that has 1:1 correspondence to the physical model.
I have a user model that is generated using Devise. I am extending this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.