Running a capistrano task in background
I'd suggest making task B an actual Rake task, and then having Capistrano call and immediately background it, e.g. https://stackoverflow.com/a/5829142/3042016
Background task with Capistrano
I found a solution, just add pty: false at the end
run "cd #{deploy_to} && export PORT=#{server_port} && export ENV=#{env} && nohup target/start > /dev/null 2>&1 &" pty: false
Resque Capistrano Deployment in Rails
It really depends on the size of your app. From my experience, generally a single Resque worker isn't much larger than your app's footprint. However, if your Resque worker will instantiate a lot of large objects, the size of the Resque instance could grow very quickly.
Check out the capistrano-resque gem. It provides all this functionality for you, plus more. :)
There are several options for this. A lot of people have followed something similar to this post about running Resque in Production and using the God gem. Personally, I've used a process similar to what is described in this post using Monit. Monit can be a bit of a pain to set up, so I'd strongly recommend checking out the God gem.
Spawn a background process in Ruby
As long as you are working on a POSIX OS you can use fork
and exec
.
fork
= Create a subprocess
exec
= Replace current process with another process
You then need to inform that your main-process is not interested in the created subprocesses via Process.detach
.
job1 = fork do
exec "/path/to/daemon01"
end
Process.detach(job1)
...
Related Topics
Gem Install Permission Problem
Ruby: How to Turn a Hash into Http Parameters
Converting an Integer to a Hexadecimal String in Ruby
Rails - Best-Practice: How to Create Dependent Has_One Relations
What's the 'Ruby Way' to Iterate Over Two Arrays at Once
Is the Server Running on Host "Localhost" (::1) and Accepting Tcp/Ip Connections on Port 5432
Looping in a Spiral Outside-In
Turning Long Fixed Number to Array Ruby
Why Aren't Do/End and {} Always Equivalent
Rails 'Parse_Query' Error on Server in Brand New App
How Does Array#Map Have Parameter to Do Something Like This
What Are the Benefits of the New Hash Syntax in Ruby 1.9
How to Dynamically Call a Math Operator in Ruby
Ruby Basic Data Type Conversion
What Is the "Right" Way to Iterate Through an Array in Ruby