views:

30

answers:

2

I have the following code in a controller

user = RegUser.create_reg_user(:some_parameters)
UserStuff.pass_user(some_parameters)
@hex = user.hex

The @hex is passed to the view and returned. The UserStuff call is taking a decent amount of time and is not actually important to the @hex which is needed for the view. Is there a way to go ahead and return the @hex and load the view and let the UserStuff process afterwards?

+2  A: 

Offload these kinds of long running "jobs" to a background queue. Probably the easiest for you to get setup and running is Delayed Job.

We use Beanstalkd (a queue) and many worker processes to handle all long-running tasks (or any tasks that takes longer than 1-2 seconds).

The beauty of having a background system to process these kinds of jobs is that you can scale quickly, you can spin-up any number of worker processes which all pull jobs from a master queue (or DB in the case of Delayed Job).

Cody Caughlan
A: 

Delayed Job is good, and easy to use. I recommend it.

allenwei