1

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.

xor
  • 2,668
  • 2
  • 28
  • 42
  • To clarify: Are tasks C-F supposed to finish before the completion of the Capistrano run, or are they long running background processes/daemons? – will_in_wi Jun 02 '16 at 11:39
  • Long running background process [I will update my question] – xor Jun 02 '16 at 12:10
  • So C-F will eventually finish, but a deployment can be considered done before they do? – will_in_wi Jun 02 '16 at 12:13
  • Yes, before deployment, I stop the servers, initiate db and asset backups and upload in background, and complete deployment and restart server. – xor Jun 02 '16 at 12:15

1 Answers1

2

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

Community
  • 1
  • 1
will_in_wi
  • 2,623
  • 1
  • 16
  • 21
  • 1
    Thanks, I made a ruby script for all four tasks combined to one, uploaded it to the server and then ran it in the background using `nohup`. Worked like a charm – xor Jun 28 '16 at 19:39