Skip to content

Commit

Permalink
Add a setting to control terminating func host (#1565)
Browse files Browse the repository at this point in the history
  • Loading branch information
ejizba committed Oct 9, 2019
1 parent 948aa62 commit 0655c7a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,11 @@
"type": "boolean",
"description": "%azureFunctions.enableOutputTimestamps%",
"default": true
},
"azureFunctions.stopFuncTaskPostDebug": {
"type": "boolean",
"description": "%azureFunctions.stopFuncTaskPostDebug%",
"default": true
}
}
}
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"azureFunctions.startJavaRemoteDebug": "Attach Debugger",
"azureFunctions.startRemoteDebug": "Start Remote Debugging",
"azureFunctions.startStreamingLogs": "Start Streaming Logs",
"azureFunctions.stopFuncTaskPostDebug": "Automatically stop the task running the Azure Functions host when a debug sessions ends.",
"azureFunctions.stopFunctionApp": "Stop",
"azureFunctions.stopStreamingLogs": "Stop Streaming Logs",
"azureFunctions.swapSlot": "Swap Slot...",
Expand Down
27 changes: 15 additions & 12 deletions src/funcCoreTools/funcHostTask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as vscode from 'vscode';
import { IActionContext, registerEvent } from 'vscode-azureextensionui';
import { delay } from '../utils/delay';
import { getWorkspaceSetting } from '../vsCodeConfig/settings';

// The name of the task before we started providing it in FuncTaskProvider.ts
export const oldFuncHostNameRegEx: RegExp = /run\s*functions\s*host/i;
Expand Down Expand Up @@ -47,21 +48,23 @@ async function stopFuncTaskIfRunning(context: IActionContext, debugSession: vsco
context.errorHandling.suppressDisplay = true;
context.telemetry.suppressIfSuccessful = true;

if (debugSession.workspaceFolder) {
const funcExecution: vscode.TaskExecution | undefined = vscode.tasks.taskExecutions.find((te: vscode.TaskExecution) => {
return te.task.scope === debugSession.workspaceFolder && isFuncHostTask(te.task);
});
if (getWorkspaceSetting<boolean>('stopFuncTaskPostDebug')) {
if (debugSession.workspaceFolder) {
const funcExecution: vscode.TaskExecution | undefined = vscode.tasks.taskExecutions.find((te: vscode.TaskExecution) => {
return te.task.scope === debugSession.workspaceFolder && isFuncHostTask(te.task);
});

if (funcExecution) {
context.telemetry.suppressIfSuccessful = false; // only track telemetry if it's actually the func task
if (funcExecution) {
context.telemetry.suppressIfSuccessful = false; // only track telemetry if it's actually the func task

const runningFuncTask: IRunningFuncTask | undefined = runningFuncTaskMap.get(debugSession.workspaceFolder);
if (runningFuncTask !== undefined) {
// Wait at least 10 seconds after the func task started before calling `terminate` since that will remove task output and we want the user to see any startup errors
await delay(Math.max(0, runningFuncTask.startTime + 10 * 1000 - Date.now()));
const runningFuncTask: IRunningFuncTask | undefined = runningFuncTaskMap.get(debugSession.workspaceFolder);
if (runningFuncTask !== undefined) {
// Wait at least 10 seconds after the func task started before calling `terminate` since that will remove task output and we want the user to see any startup errors
await delay(Math.max(0, runningFuncTask.startTime + 10 * 1000 - Date.now()));

if (runningFuncTaskMap.get(debugSession.workspaceFolder) === runningFuncTask) {
funcExecution.terminate();
if (runningFuncTaskMap.get(debugSession.workspaceFolder) === runningFuncTask) {
funcExecution.terminate();
}
}
}
}
Expand Down

0 comments on commit 0655c7a

Please sign in to comment.