You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Auto-run task on folder close in addition to open #65986
Thanks very much for adding "run on folder open" to tasks. I wish to request a "run on folder close" to complement this to e.g. stop services that are started on folder open.
I describe my use case in this comment: #54775 (comment).
Another use case is process clean-up. For instance, when using Debug Start with nodemon-hosted Node JS processes, if you quit VSCode "node" processes are left orphaned (and consuming CPU) as shown in Activity Monitor. I would like to do process clean-up in a folder-close task rather than manually in Activity Monitor after quitting VS Code.
Reacted by John Weisz, Marc, Justin Grant, Jeroen Rothbauer, Chris Djali, lerit, German, cunning-seal, Isaac Bedard, Kenichi Kamiya and 6 more
Hi Alex Ross (@alexr00), nice to hear from you. I tend to set a number of things up before debug such as "stop remote process on server and activate SSH port forwarding to local" and e.g. start local Redis service which would be really nice to reverse on folder close. These are things you don't want to turn on and off each time you start and stop debugging. The clean-up stuff is also not very appropriate to run as a postDebugTask as my two commands here, "killall node" and "killall Chromium" (for Puppeteer debris), both have undesirable effects when run as a postDebugTask. (The undesirable effects are that "killall node" also kills a legitimate process - IIRC it kills nodemon - and in fact would also stop all other Node debug processes (we don't yet have a Stop All command but this might get close!) and "killall Chromium" would present examination of failed Puppeteer tests.)
Appreciate this might not be the most urgent thing in the world but I think it's the right approach and is symmetrical with the fantastic task-run-on-folder-open you implemented. 😀
We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.
I've just began using the onOpen run config of Tasks as a way to automatically start a development server when I open my workspace. I would like to be able to use a onClose one to stop them as well. So, that is just what my use case for such a feature would be. Just to add to the mix of people requesting this feature for if and when it gets worked on.
Reacted by Frisbee, German, MunsMan, Piotr Zawiślak, Miguel Rodriguez, Kevin Erdiza Yogatama and Andreas Böhm
This is nice because the task disappears when the services has started, and then avoiding clutter my terminal view. However with this config there doesn't seem to be any way of stopping the services, once I leave the folder / VSCode.
My current solution
I do not run docker compose in detached mode. This takes advantage of the fact that if the task is left running indefinitely, you can emulate folderClose by handling the exit signal sent by VSCode to the task, which in this case stops the docker compose services. Here is an example with a bash script:
#!/bin/bashon_folder_close() {
echo This is run when the folder / VSCode closes
trap - SIGINT
kill -- -$$
}
trap on_folder_close SIGINT
echo This is run when the folder is opened
sleep infinity
While this produce the expected behavior, someone else should probably look it over, since I am not an expert on signal handling or bash. The disadvantage here is that the task will always be visible in the terminal view, but it helps if you set presentation.reveal to "silent". Here is my final task:
Alex Ross (@alexr00) I know this has been closed as out of scope, but is there any way to get this considered again?
I have another use case where this would really help:
I have a local Kubernetes cluster and one running on GKE. My Ingress points to a fixed domain, i.e., stocksalot.tech. While I am developing locally, I modify my /etc/hosts file to redirect this domain to localhost. But this is a pretty manual process where I have to open and edit the file before every development session and again open and edit it after the session and then close VSCode. If I can configure a task to automatically reset the hosts file before closing VSCode, it would really beneficial.
I imagine a feature like this would be quite powerful to use in addition to the Cloud Changes feature. You could save changes on folderClose and retrieve them elsewhere on folderOpen.
Activity
alexr00 commentedon Oct 8, 2019
On your launch config you can specify a
postDebugTask. Does that solve your use-case?markm77 commentedon Oct 8, 2019
Hi Alex Ross (@alexr00), nice to hear from you. I tend to set a number of things up before debug such as "stop remote process on server and activate SSH port forwarding to local" and e.g. start local Redis service which would be really nice to reverse on folder close. These are things you don't want to turn on and off each time you start and stop debugging. The clean-up stuff is also not very appropriate to run as a
postDebugTaskas my two commands here, "killall node" and "killall Chromium" (for Puppeteer debris), both have undesirable effects when run as apostDebugTask. (The undesirable effects are that "killall node" also kills a legitimate process - IIRC it kills nodemon - and in fact would also stop all other Node debug processes (we don't yet have a Stop All command but this might get close!) and "killall Chromium" would present examination of failed Puppeteer tests.)Appreciate this might not be the most urgent thing in the world but I think it's the right approach and is symmetrical with the fantastic task-run-on-folder-open you implemented. 😀
alexr00 commentedon Oct 9, 2019
@markfinlabs makes sense, I just wanted to make sure there wasn't already something out there that would solve the problem!
markm77 commentedon Oct 9, 2019
Sure, no trouble.
vscode-triage-bot commentedon Nov 9, 2020
We closed this issue because we don't plan to address it in the foreseeable future. You can find more detailed information about our decision-making process here. If you disagree and feel that this issue is crucial: We are happy to listen and to reconsider.
If you wonder what we are up to, please see our roadmap and issue reporting guidelines.
Thanks for your understanding and happy coding!
alexclst commentedon Feb 13, 2021
I've just began using the
onOpenrun config of Tasks as a way to automatically start a development server when I open my workspace. I would like to be able to use aonCloseone to stop them as well. So, that is just what my use case for such a feature would be. Just to add to the mix of people requesting this feature for if and when it gets worked on.lassebomh commentedon Sep 6, 2023
I would also love this.
In my current setup I use
"runOn": "folderOpen"to run docker compose task, that starts my cache and database:{ "label": "Start development services", "type": "docker-compose", "presentation": { "reveal": "silent", "close": true, }, "runOptions": { "runOn": "folderOpen", }, "dockerCompose": { "up": { "detached": true, "build": true }, "files": [ "${workspaceFolder}/.ci/dev/docker-compose.yml" ], }, },This is nice because the task disappears when the services has started, and then avoiding clutter my terminal view. However with this config there doesn't seem to be any way of stopping the services, once I leave the folder / VSCode.
My current solution
I do not run docker compose in detached mode. This takes advantage of the fact that if the task is left running indefinitely, you can emulate
folderCloseby handling the exit signal sent by VSCode to the task, which in this case stops the docker compose services. Here is an example with a bash script:While this produce the expected behavior, someone else should probably look it over, since I am not an expert on signal handling or bash. The disadvantage here is that the task will always be visible in the terminal view, but it helps if you set presentation.reveal to "silent". Here is my final task:
{ "label": "Start development services", "type": "docker-compose", "presentation": { "reveal": "silent", }, "runOptions": { "runOn": "folderOpen", }, "dockerCompose": { "up": { "detached": false, "build": true }, "files": [ "${workspaceFolder}/docker-compose.yml" ], }, },Hyperclaw79 commentedon Sep 22, 2023
Alex Ross (@alexr00) I know this has been closed as out of scope, but is there any way to get this considered again?
I have another use case where this would really help:
I have a local Kubernetes cluster and one running on GKE. My Ingress points to a fixed domain, i.e., stocksalot.tech. While I am developing locally, I modify my
/etc/hostsfile to redirect this domain to localhost. But this is a pretty manual process where I have to open and edit the file before every development session and again open and edit it after the session and then close VSCode. If I can configure a task to automatically reset the hosts file before closing VSCode, it would really beneficial.dylan-k commentedon Jan 10, 2024
I imagine a feature like this would be quite powerful to use in addition to the Cloud Changes feature. You could save changes on folderClose and retrieve them elsewhere on folderOpen.