Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run several tasks as a group?

I created two tasks to assist me in the development of a web site:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "build site",
            "command": "jekyll b --watch --incremental",
            "type": "shell",
            "group": "build"
        },
        {
            "taskName": "serve site",
            "command": "./_devd -ol _site",
            "type": "shell",
            "group": "build"
        }
    ]
}

I can start them one by one with F1 → Run Task (so I need to issue the sequence twice, once for each task) and I end up with two tasks running at the same time.

Is it possible to automate this and run a group of tasks at the same time? I thought that the group entry would, well, group them together but it is not the case (they are just recognized as belonging to the build or test group - and I did not find a way to start the whole group at once).

like image 642
WoJ Avatar asked Aug 03 '17 13:08

WoJ


People also ask

How do you run multiple codes in VS code?

You can have multiple windows open and they'll each have their own terminal. Or run one in the vscode terminal and one in a regular terminal window. cd project/python && python3 project.py & cd project/node && node . The above runs a python and nodejs project from 1 command.


1 Answers

You can use the "dependsOn" attribute. If you want to run the "build site" task first, add it as the "dependsOn" of the "serve site" task. If you want both to run together, make another task that depends on both the "build site" and "serve site" tasks.

Here is an example of building the site before serving it:

{
  "taskName": "build site",
  "command": "jekyll b --watch --incremental",
  "type": "shell",
  "group": "build"
},
{
  "taskName": "serve site",
  "command": "./_devd -ol _site",
  "type": "shell",
  "group": "build",
  "dependsOn": "build site" // <--- Added this
},

Not aware of a cleaner way to do this with long running tasks but...

Here is an example of running both tasks at the same time:

{
  "taskName": "Run Everything", // <-- Bind this task to a key
  "dependsOn": [ "build site", "serve site" ]
},
{
  "taskName": "build site",
  "command": "jekyll b --watch --incremental",
  "type": "shell"
},
{
  "taskName": "serve site",
  "command": "./_devd -ol _site",
  "type": "shell"
}

Update: Here's a link to the documentation for the new tasks.json template (v2.0.0). The portion relevant to this question is that taskName has been renamed to label, but dependsOn's value remains the same.

like image 57
alexriedl Avatar answered Oct 06 '22 22:10

alexriedl