Threading in Rails

Hello,

I was wondering if someone can point me how to invoke threads from an action in a controller. Basically, in an action, I want to do some tasks asynchronously for which user need not wait.

It isn't safe (at least not now) to create threads in Rails, but you
can use something like Background Job ->
http://codeforpeople.com/lib/ruby/bj/bj-1.0.1/README

Will look into it.

Does this background job maintains a queue sort of thing? If yes, then how does some tasks can be concurrently executed?

Background job usually runs a job at a time, which is cool as Ruby
itself is almost "single threaded", but if you want a solution with
concurrent job execution, you can try SkyNet ->
http://skynet.rubyforge.org/

Check out the last two Railscasts.

http://railscasts.com/episodes/127-rake-in-background

http://railscasts.com/episodes/128-starling-and-workling

I think this might be what you need.

I installed skynet in my rails application using
$skynet_install --rails .

After this, when I try to start my server (Mongreal), it throws me following error.

=> Booting Mongrel (use ‘script/server webrick’ to force WEBrick)

=> Rails application starting on http://127.0.0.1:3005
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Starting Mongrel listening at 127.0.0.1:3005

** Starting Rails with development environment…
Exiting
/home/jaikishan/aptana/
plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’: no such file to load – skynet (MissingSourceFile)

from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `new_constants_in'
from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:318:in `require'

from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496
from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'
from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496:in `new_constants_in'

from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:318:in `require'
from /home/jaikishan/aptana/plugins/org.jruby_1.1.0.5965_RC2p2/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:496

 ... 35 levels...
from /home/jaikishan/aptana/workspace/Analytics/./script/server:3
from -e:2:in `load'
from -e:2

What to do now?