bake icon indicating copy to clipboard operation
bake copied to clipboard

Async Execution

Open agucova opened this issue 6 years ago • 5 comments

Is there any way to run two tasks simultaneously?

I'm not sure if this is an intended use case (continuous tasks).

I have a Bakefile like this:

launch/dev: launch/huey launch/flask

launch/huey:
    huey_consumer app.main

launch/flask:
    flask run

And my intention would be to run both launch/huey and launch/flask at the same time when launch/dev is called in, order to test an app.

agucova avatar Sep 19 '19 22:09 agucova

Use bash to do it!

kennethreitz avatar Sep 20 '19 23:09 kennethreitz

But given that they are declared as separated tasks, how can I use bash to call both?

I can do this:

launch/dev:
    huey_consumer & flask run

But can bash call a task defined in the Bakefile?

agucova avatar Sep 21 '19 00:09 agucova

launch/dev:
    bake launch/huey & bake launch/flask

launch/huey:
    huey_consumer app.main

launch/flask:
    flask run

Make sure to use a latest release for this.

:sparkles: :cake: :sparkles:

kennethreitz avatar Sep 23 '19 01:09 kennethreitz

hello: hello/reuse hello/reuse/concurrent
    echo "You just ran $(red 'hello') directly, then indirectly (via bake+bash; 6 times, concurrently!)"
hello/basic:
    sleep 2
    echo "[$(red $(uuidgen))] hello!"
hello/reuse:
    bake hello/basic

hello/reuse/concurrent:
    bake hello/reuse &
    bake hello/reuse &
    bake hello/reuse &
    bake hello/reuse &
    bake hello/reuse &
    bake hello/reuse
$ bake hello
 + Executing hello/reuse:
 |  [C286C3C1-7C57-4FB1-8981-548A03BCD103] hello!
 + Executing hello/reuse/concurrent:
 |  [924F205E-11B6-43D1-8451-8FFBEE7A2536] hello!
 |  [3BDDC2E8-0329-4BC6-B8BB-D48506743E16] hello!
 |  [5C665A12-6CEF-431D-B9AE-76B217F17EA9] hello!
 |  [D71C2CB2-7C9A-4702-BD5C-EDCFCF4A9EC4] hello!
 |  [436F5009-B6AC-4C90-8E11-05E2F2BBED1C] hello!
 |  [D9BB86A7-A7A6-4ADE-8755-C21296B7AD84] hello!
 + Executing hello:
 |  You just ran hello directly, then indirectly (via bake+bash; 6 times, concurrently!)
 + Done.

kennethreitz avatar Sep 23 '19 01:09 kennethreitz

This works because bake automatically sets the BAKE_SILENT environment variable for the tasks that run underneath it, which is like passing the bake --silent flag.

kennethreitz avatar Sep 23 '19 03:09 kennethreitz