Skip to content

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

Closed
alpalla wants to merge 4 commits into
microsoft:mainfrom
alpalla:feature/task-instance-policy
Closed

Fixes #90125 - Add a task instancePolicy to task runOptions#117129
alpalla wants to merge 4 commits into
microsoft:mainfrom
alpalla:feature/task-instance-policy

Conversation

@alpalla

@alpalla alpalla commented Feb 20, 2021

Copy link
Copy Markdown
Contributor

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

alexr00 commented Feb 22, 2021

Copy link
Copy Markdown
Member

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

blooop commented Jul 14, 2021

Copy link
Copy Markdown

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

@alexr00 alexr00 left a comment

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.

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.

Comment thread src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts Outdated
Comment thread src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts Outdated
@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

alpalla commented Sep 3, 2021

Copy link
Copy Markdown
Contributor Author

@alexr00 ping 🙂

@MikolajKolek

Copy link
Copy Markdown

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

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

@dn54321

dn54321 commented Dec 19, 2022

Copy link
Copy Markdown

Any updates to this ticket?

@alexr00 alexr00 assigned meganrogge and unassigned alexr00 Dec 19, 2022
@meganrogge

Copy link
Copy Markdown
Collaborator

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

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Copy link
Copy Markdown

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
Copy Markdown
Collaborator

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

vivodi commented Dec 29, 2024

Copy link
Copy Markdown

Is this still relevant?

@dimateos

dimateos commented Jan 9, 2025

Copy link
Copy Markdown

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

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
Copy Markdown
Collaborator

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
…ish/tweak.

Co-authored-by: alpalla <46252231+alpalla@users.noreply.github.com>
meganrogge added a commit that referenced this pull request May 12, 2025
…ish/tweak.

Co-authored-by: alpalla <46252231+alpalla@users.noreply.github.com>
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 <46252231+alpalla@users.noreply.github.com>
@meganrogge

Copy link
Copy Markdown
Collaborator

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

alpalla commented Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

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