-
Notifications
You must be signed in to change notification settings - Fork 35.7k
Fixes #32264 - Allow N instances of the same task #89872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #32264 - Allow N instances of the same task #89872
Conversation
…e task. If another instance of a task is run, a clone of that task will be created and its ID will be modified by appending '|<COUNTER>' to the original task ID, where <COUNTER> is incremented each time an instance of the same task is created. This way it is possible to figure out if any given task is an instance of another task by comparing the IDs before the '|' (pipe) symbol. The unique counter appended at the end allows the insertion of the same task in the activeTasks dictionary. An "instances" data structure was added to keep track of the number of instances of a task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good PR! There are just a few changes before it can be merged.
…er private because they only serve to maintain state and shouldn't be modified outside the class. Removed reveal and focus code in response to recent changes. Changed default RunOnOptions when reading from configuration for 'instances' attribute to value of 1.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you!
|
Will this be exposed in the Tasks API as well? |
|
Not at the moment. Do you want it in the tasks api? |
|
Yes, I have a use case for it. Though after rereading this, it seems like this only solves part of the issue, as you're still prompted each time you exceed the instance limit (so it sounds like #32264 shouldn't have been closed just yet while In general, I don't see much of a reason to only expose some functionality of |
|
That's fair. I don't really want to expose every |
|
I could actually also see an extension wanting to contribute a task with However, it could be argued that it's redundant since extensions can already do this in a more flexible manner via the |
Summary
RunOptions.(i)appended to the quick pick entry label to indicate that the task is an instance of an already running task.For example if 3 instances of task
fooare running, the QuickPick would display:Implementation notes
Distinguishing between multiple instances of the same task
When a task is run in
terminalTaskSystem, if another instance can be created, the task that the user selected is cloned and itsidis modified to have form<ORIGINAL_TASK_ID>|<COUNTER>.The counter gets incremented each time an instance of the same task is created. The cloned task is then run like any other task.
This makes it possible to check if a task is an instance of another task because all instances of a task will have the
<ORIGINAL_TASK_ID>substring in common in their respective ids.Tracking multiple instances of the same task.
The
<ORIGINAL_TASK_ID>substring shared by all instances serves as the key in a dictionary where the value is anInstanceManagerobject that stores information related to all instances of a task such as the number of currently active instances.How to test changes
Create a
tasks.jsonand set theinstancesproperty. Here is an example configuration:{ "version": "2.0.0", "tasks": [ { "label": "echo", "type": "shell", "command": "sleep 20 && echo Hello", "runOptions": { "instances": 3} } ] }You can then execute the
echotask, ensure that it never runs more than 3 instances of itself and that if a 4th instance is attempted, you should be prompted to either terminate or restart the last instance ofecho.