Skip to content

Fixes #90125 - Add a task instancePolicy to task runOptions#90914

Closed
alpalla wants to merge 2 commits into
microsoft:mainfrom
alpalla:feature/runoptions-instancepolicy
Closed

Fixes #90125 - Add a task instancePolicy to task runOptions#90914
alpalla wants to merge 2 commits into
microsoft:mainfrom
alpalla:feature/runoptions-instancepolicy

Conversation

@alpalla

@alpalla alpalla commented Feb 18, 2020

Copy link
Copy Markdown
Contributor

Summary

Fixes #90125. Added an instancePolicy to runOptions. The instancePolicy is applied when creating a new instance of a task once the instanceLimit has been reached.
The instancePolicy is as follows:

  1. terminateNewest: the newest instance is terminated
  2. terminateOldest: the oldest instance is terminated
  3. prompt: the QuickPick is shown and the user picks an instance to restart (this is the default option)
  4. warn: do nothing (do not terminate an existing instance or create a new one) and show a warning that indicates that the instanceLimit has been reached
  5. silent: do nothing

Implementation notes

  • any task selected to be "terminated" by the instancePolicy is effectively restarted
  • the TerminalTaskSystem getLastInstance() method has been expanded in scope and is now called getNthInstance. As the name suggests it returns the Nth instance of a task given a number. If no index is given, it returns the last instance by default. I used a for loop instead of doing a forEach on Object.keys so that I could exit early once the right instance was found
  • when an instance is created, slightly changed the way I previously set its id so as to avoid cases in which an instance of an instance was being created and the id would be appended with |<COUNTER> multiple times

Testing changes

Create a tasks.json and set the instancLimit and instancePolicy properties. Here is an example configuration:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "sleep 20 && echo Hello",
            "runOptions": {
                "instanceLimit": 2,
                "instancePolicy": "terminateOldest"
            }
        }
    ]
}

Ensure that once the instanceLimit is reached, the chosen instancePolicy behaves as described at the beginning of this PR.

P.S.

I would suggest not having the prompt option as the default option simply because in the default case where instanceLimit == 1, the user would be shown the QuickPick which would contain only one entry since there is only one active instance. Personally, I think it would make more sense to have another instancePolicy option which would ask the user to terminate or restart the last instance. This would maintain the current behavior and use the current terminate/restart notification, while I think being the least confusing option in the case where runOptions is set to all default settings.

…ce of a task once the instanceLimit has been reached.
@alpalla

alpalla commented Apr 2, 2020

Copy link
Copy Markdown
Contributor Author

@alexr00 any updates regarding anything I can do to move forward with this PR? 😃

@sky126

sky126 commented Apr 16, 2020

Copy link
Copy Markdown

need this feature

},
instancePolicy: {
type: 'string',
enum: ['terminateNewest', 'terminateOldest', 'prompt', 'warn', 'silent'],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add an enum description for this?

@alexr00

alexr00 commented Apr 30, 2020

Copy link
Copy Markdown
Member

I haven't had a chance to do a full review yet, but I hope to next week. Can you resolve the conflicts?

@alpalla

alpalla commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

Sure! I'll resolve the conflicts and add that enum description 👍

@alpalla

alpalla commented May 1, 2020

Copy link
Copy Markdown
Contributor Author

@alexr00 I can't resolve the conflicts and test the resulting code locally because it seems like a couple of things are broken in the latest build. The main issues are:

  1. the instanceLimit doesn't seem to be respected anymore (meaning I can create K instances of a task with a limit of N where K > N).
  2. If I create n instances of a task and let all instances run to completion, it looks like they are not automatically terminated because all instances are still visible as options to terminate.

I can resolve the conflicts via GitHub without testing the resulting code first but I'm a little hesitant to do so. Let me know how I should proceed, thanks!

@onelivesleft

Copy link
Copy Markdown

Is this feature dead in the water? Would be a great addition.

@alexr00

alexr00 commented Feb 22, 2021

Copy link
Copy Markdown
Member

Closing in favor of the newer one: #117129

@alexr00 alexr00 closed this Feb 22, 2021
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

4 participants