Search code examples
deploymentrakebackgroundworkerdaemoncapistrano3

Running a capistrano task in background


I have a cap task that call multiple other long running cap tasks:

So lets say I have a task named A

From within this cap task I (depending on condition) call another cap task lets say B.

cap task B sequentially calls 4 more cap tasks c, D, E, & ,F

So be is something like this:

task :B do
    on roles(:all) do
        invoke 'tasks:C'
        invoke 'tasks:D'
        Rake::Task['db:E'].invoke("arg1", "arg2")
        Rake::Task['db:F'].invoke("arg1", "arg2")
    end
end

Each of C, D, E & F are long running and must run sequentially in same order as specified.

Basically tasks C to F are db & assets zipping and uploading tasks which might take long time, so they must not hinder the cap deployment process and should run independently in background.

So I need a way to call task B from task A so that it runs in async mode, and rest of cap tasks during deployment keep running.


Solution

  • 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