Skip to content

Conversation

@alpalla
Copy link
Contributor

@alpalla alpalla commented Feb 20, 2021

Fixes #90125.
This pull request replaces the old one I opened (#90914) for the same issue almost a year ago.

Summary

Added an instancePolicy to runOptions. The instancePolicy is applied when creating a new instance of a task once the instanceLimit has been reached.

There are five options for instancePolicy:

  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
  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

prompt is the default option.

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": "date && sleep 300",
            "runOptions": {
                "instanceLimit": 2,
                "instancePolicy": "terminateOldest"
            }
        }
    ]
}

Ensure that once the instanceLimit is reached, the chosen instancePolicy behaves as intended.


@alexr00 to get things working I had to revert some changes you made for Fix unlimited instances of recent tasks bug.
In particular here and here.
I just want to be sure there are no regressions.

creating a new instance of a task, once the
instanceLimit has been reached.
@alexr00
Copy link
Member

alexr00 commented Feb 22, 2021

Thanks for the updated PR! I will try to take a look in March.

@alexr00 alexr00 added this to the March 2021 milestone Feb 22, 2021
@alexr00 alexr00 modified the milestones: March 2021, April 2021 Mar 24, 2021
@alexdima alexdima modified the milestones: April 2021, May 2021 Apr 30, 2021
@alexr00 alexr00 modified the milestones: May 2021, June 2021 Jun 2, 2021
@alexr00 alexr00 modified the milestones: June 2021, July 2021 Jun 29, 2021
@blooop
Copy link

blooop commented Jul 14, 2021

I am interested in this feature, as the current task system require more manual clicking (to restart) that just using the terminal.

Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! In May of 2020 I made some changes to task instance to fix some related bugs, but it looks like this updated PR doesn't take those changes into account.

@alexr00 alexr00 removed this from the July 2021 milestone Jul 16, 2021
@alpalla alpalla requested a review from alexr00 August 7, 2021 10:44
@alpalla
Copy link
Contributor Author

alpalla commented Sep 3, 2021

@alexr00 ping 🙂

@MikolajKolek
Copy link

Hello, I'm sorry if I'm being annoying, but this has been waiting to be reviewed for over the last 4 months with completely no progress. This feature seems really quite useful, so I'd appreciate someone at least looking at this

@victorvianna
Copy link

@alexr00 Is this PR on the right path? If someone finds time to rebase it, will it be LGTM-ed?

@dn54321
Copy link

dn54321 commented Dec 19, 2022

Any updates to this ticket?

@alexr00 alexr00 assigned meganrogge and unassigned alexr00 Dec 19, 2022
@meganrogge
Copy link
Contributor

There are some conflicts - I will try to make time to review it if those get fixed

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

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

The code revisions refine the logic for selecting instances to terminate by directly comparing task IDs instead of common prefixes. The updated code simplifies the filtering process to match tasks based on their exact IDs rather than a shared prefix, which enhances accuracy in identifying the correct instance. This change eliminates potential mismatches caused by common ID prefixes and ensures that users are prompted to select the exact instance they intend to terminate, improving both precision and user experience.

@meganrogge meganrogge added this to the August 2024 milestone Jul 23, 2024
} else {
this._taskSystem?.revealTask(executeResult.task);
}
this.handleInstancePolicy(executeResult.task, executeResult.task.runOptions!.instancePolicy);
Copy link
Contributor

Choose a reason for hiding this comment

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

we are now missing this check for task visibility this._taskSystem?.isTaskVisible(executeResult.task). If a task is not visible, I don't think it'll be revealed with this change?

@meganrogge meganrogge removed this from the August 2024 milestone Aug 2, 2024
@vivodi
Copy link

vivodi commented Dec 29, 2024

Is this still relevant?

@dimateos
Copy link

dimateos commented Jan 9, 2025

IMO #90125 is still relevant: avoid having to manually terminate tasks... or the workaround to terminate ALL tasks

This PR seems to be the most recent one referencing the issue.

@y2kbugger
Copy link

Also here from #90125 Would be really nice for any task that doesn't have it's own filewatcher built in

@meganrogge meganrogge added this to the May 2025 milestone May 12, 2025
@meganrogge
Copy link
Contributor

The conflicts are pretty confusing, @alpalla , would you consider creating a new branch based on main with your changes? If not, I might do so and just add you as a co-author.

meganrogge added a commit that referenced this pull request May 12, 2025
meganrogge added a commit that referenced this pull request May 12, 2025
meganrogge added a commit that referenced this pull request May 12, 2025
Bring changes from #117129 to new branch to avoid conflicts. Also polish/tweak.

Co-authored-by: alpalla <[email protected]>
@meganrogge
Copy link
Contributor

Closing in favor of #248747, but will be sure you are credited with this work in the release notes @alpalla! Thanks so much!

@meganrogge meganrogge closed this May 16, 2025
@alpalla
Copy link
Contributor Author

alpalla commented Jun 12, 2025

The conflicts are pretty confusing, @alpalla , would you consider creating a new branch based on main with your changes? If not, I might do so and just add you as a co-author.

@meganrogge sorry I didn't see your comment, thank you so much for taking care of this 🙏🏻

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jun 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a task instancePolicy to task runOptions.