Skip to content

Commit

Permalink
Keep track of whether func task is running for pickProcess (#575)
Browse files Browse the repository at this point in the history
I incorrectly made the assumption that `vscode.tasks.taskExecutions` was the list of _running_ tasks, but it's actually a list of tasks that have _ever_ run in this session, even if they're not running right now.
  • Loading branch information
ejizba committed Sep 10, 2018
1 parent 631a368 commit 6b036fb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

All notable changes to the "azurefunctions" extension will be documented in this file.

## 0.10.2 - 2018-09-10

### Fixed

- Debugging C# functions after fixing a build break fails with error "Failed to stop previous running Functions host..." [#534](https://github.com/Microsoft/vscode-azurefunctions/issues/534)

## 0.10.1 - 2018-09-06

### Added
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-azurefunctions",
"displayName": "Azure Functions",
"description": "%extension.description%",
"version": "0.10.1",
"version": "0.10.2",
"publisher": "ms-azuretools",
"icon": "resources/azure-functions.png",
"aiKey": "AIF-d9b70cd4-b9f9-4d70-929b-a071c400b217",
Expand Down Expand Up @@ -644,7 +644,7 @@
"request-promise": "^4.2.2",
"semver": "^5.5.0",
"vscode-azureappservice": "^0.21.0",
"vscode-azureextensionui": "^0.17.0",
"vscode-azureextensionui": "^0.17.4",
"vscode-azurekudu": "^0.1.8",
"vscode-extension-telemetry": "^0.0.18",
"vscode-nls": "^2.0.2",
Expand Down
18 changes: 17 additions & 1 deletion src/commands/pickFuncProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import * as vscode from 'vscode';
import { Task, TaskExecution } from 'vscode';
import { ext } from 'vscode-azureappservice/lib/extensionVariables';
import { IActionContext, UserCancelledError } from 'vscode-azureextensionui';
import { extensionPrefix, isWindows } from '../constants';
import { validateFuncCoreToolsInstalled } from '../funcCoreTools/validateFuncCoreToolsInstalled';
Expand All @@ -13,6 +14,21 @@ import { getFuncExtensionSetting } from '../ProjectSettings';
import { tryFetchNodeModule } from '../utils/tryFetchNodeModule';
import { funcHostTaskLabel } from './createNewProject/IProjectCreator';

let isFuncTaskRunning: boolean = false;
export function initPickFuncProcess(): void {
ext.context.subscriptions.push(vscode.tasks.onDidEndTask((e: vscode.TaskEndEvent) => {
if (isFuncTask(e.execution.task)) {
isFuncTaskRunning = false;
}
}));

ext.context.subscriptions.push(vscode.tasks.onDidStartTask((e: vscode.TaskEndEvent) => {
if (isFuncTask(e.execution.task)) {
isFuncTaskRunning = true;
}
}));
}

export async function pickFuncProcess(actionContext: IActionContext): Promise<string | undefined> {
if (!await validateFuncCoreToolsInstalled(true /* forcePrompt */)) {
throw new UserCancelledError();
Expand Down Expand Up @@ -49,7 +65,7 @@ function isFuncTask(task: Task): boolean {

async function stopFuncTaskIfRunning(): Promise<void> {
const funcExecution: TaskExecution | undefined = vscode.tasks.taskExecutions.find((te: TaskExecution) => isFuncTask(te.task));
if (funcExecution) {
if (funcExecution && isFuncTaskRunning) {
const waitForEndPromise: Promise<void> = new Promise((resolve: () => void, reject: (e: Error) => void): void => {
const listener: vscode.Disposable = vscode.tasks.onDidEndTask((e: vscode.TaskEndEvent) => {
if (isFuncTask(e.execution.task)) {
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { ILogStreamTreeItem } from './commands/logstream/ILogStreamTreeItem';
import { startStreamingLogs } from './commands/logstream/startStreamingLogs';
import { stopStreamingLogs } from './commands/logstream/stopStreamingLogs';
import { openInPortal } from './commands/openInPortal';
import { pickFuncProcess } from './commands/pickFuncProcess';
import { initPickFuncProcess, pickFuncProcess } from './commands/pickFuncProcess';
import { remoteDebugFunctionApp } from './commands/remoteDebugFunctionApp';
import { renameAppSetting } from './commands/renameAppSetting';
import { restartFunctionApp } from './commands/restartFunctionApp';
Expand Down Expand Up @@ -124,6 +124,8 @@ export function activate(context: vscode.ExtensionContext): void {
registerCommand('azureFunctions.debugFunctionAppOnAzure', async (node?: IAzureNode<FunctionAppTreeItem>) => await remoteDebugFunctionApp(outputChannel, ui, tree, node));
registerCommand('azureFunctions.deleteProxy', async (node?: IAzureNode) => await deleteNode(tree, ProxyTreeItem.contextValue, node));
registerCommand('azureFunctions.uninstallFuncCoreTools', async () => await uninstallFuncCoreTools());

initPickFuncProcess();
});
}

Expand Down

0 comments on commit 6b036fb

Please sign in to comment.