Skip to content

Commit 26e84b7

Browse files
JLargent42Jacob Largent
andauthored
feat(appcomposer): add sync success/fail handling (#1521)
* feat(appcomposer): add sync success/fail handling Problem: The Sync button has no success/failure handling. Solution: This sends responses to the webview based on the status of the Sync command. It also adds a telemetry event when the user clicks the Sync button inside Composer. * fix(appcomposer): remove unused message type, add deploy telemetry * fix(appcomposer): update deployCompleted telemetry description --------- Co-authored-by: Jacob Largent <[email protected]>
1 parent 6a3f6be commit 26e84b7

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

src/applicationcomposer/handleMessage.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
AddFileWatchRequestMessage,
1717
GenerateResourceRequestMessage,
1818
MessageType,
19+
DeployRequestMessage,
1920
} from './types'
2021
import { saveFileMessageHandler } from './messageHandlers/saveFileMessageHandler'
2122
import { addFileWatchMessageHandler } from './messageHandlers/addFileWatchMessageHandler'
@@ -33,7 +34,7 @@ export async function handleMessage(message: unknown, context: WebviewContext) {
3334
if (messageType === MessageType.REQUEST) {
3435
switch (command) {
3536
case Command.INIT:
36-
await initMessageHandler(context)
37+
void initMessageHandler(context)
3738
break
3839
case Command.LOAD_FILE:
3940
void loadFileMessageHandler(message as LoadFileRequestMessage, context)
@@ -45,7 +46,7 @@ export async function handleMessage(message: unknown, context: WebviewContext) {
4546
void addFileWatchMessageHandler(message as AddFileWatchRequestMessage, context)
4647
break
4748
case Command.DEPLOY:
48-
deployMessageHandler(context)
49+
void deployMessageHandler(message as DeployRequestMessage, context)
4950
break
5051
case Command.GENERATE_RESOURCE:
5152
void generateResourceHandler(message as GenerateResourceRequestMessage, context)

src/applicationcomposer/messageHandlers/deployMessageHandler.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,31 @@
44
*/
55

66
import vscode from 'vscode'
7-
import { WebviewContext } from '../types'
7+
import { Command, DeployRequestMessage, DeployResponseMessage, MessageType, WebviewContext } from '../types'
8+
import { SamSyncResult } from '../../shared/sam/sync'
9+
import { telemetry } from '../../shared/telemetry/telemetry'
810

9-
export function deployMessageHandler(context: WebviewContext) {
10-
vscode.commands.executeCommand('aws.samcli.sync')
11+
export async function deployMessageHandler(message: DeployRequestMessage, context: WebviewContext) {
12+
// SAM already handles success/failure, so we only log that the user clicked the deploy button
13+
telemetry.appcomposer_deployClicked.emit()
14+
const args = context.textDocument.uri
15+
/* TODO Rework this command so that a failure case is returned
16+
* We don't want to override the SAM Sync telemetry. The SAM telemetry catches all errors,
17+
* so we instead check for an undefined response to determine failure. The downside is that
18+
* we don't get failure reasons.
19+
*/
20+
const result = (await vscode.commands.executeCommand('aws.samcli.sync', args)) as SamSyncResult
21+
if (result?.isSuccess) {
22+
vscode.window.showInformationMessage('SAM Sync succeeded!')
23+
telemetry.appcomposer_deployCompleted.emit({ result: 'Succeeded' })
24+
} else {
25+
telemetry.appcomposer_deployCompleted.emit({ result: 'Failed' })
26+
}
27+
const response: DeployResponseMessage = {
28+
command: Command.DEPLOY,
29+
messageType: MessageType.RESPONSE,
30+
eventId: message.eventId,
31+
isSuccess: result?.isSuccess,
32+
}
33+
context.panel.webview.postMessage(response)
1134
}

src/applicationcomposer/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ export interface FileChangedMessage extends Message {
7474
fileContents: string
7575
}
7676

77+
export interface DeployRequestMessage extends Message {
78+
eventId: string
79+
}
80+
81+
export interface DeployResponseMessage extends Message {
82+
eventId: string
83+
isSuccess: boolean
84+
}
85+
7786
export interface RequestMessage extends Message {
7887
command: Command
7988
}

src/shared/sam/sync.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,12 @@ export async function prepareSyncParams(arg: vscode.Uri | AWSTreeNodeBase | unde
528528
return baseParams
529529
}
530530

531+
export type SamSyncResult = {
532+
isSuccess: boolean
533+
}
534+
531535
export function registerSync() {
532-
async function runSync(deployType: SyncParams['deployType'], arg?: unknown) {
536+
async function runSync(deployType: SyncParams['deployType'], arg?: unknown): Promise<SamSyncResult> {
533537
telemetry.record({ syncedResources: deployType === 'infra' ? 'AllResources' : 'CodeOnly' })
534538

535539
const connection = Auth.instance.activeConnection
@@ -550,6 +554,9 @@ export function registerSync() {
550554

551555
try {
552556
await runSamSync({ ...params, connection })
557+
return {
558+
isSuccess: true,
559+
}
553560
} catch (err) {
554561
throw ToolkitError.chain(err, 'Failed to sync SAM application', { details: { ...params } })
555562
}

src/shared/telemetry/vscodeTelemetry.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,14 @@
522522
"description": "Called after opening a template",
523523
"metadata": [{ "type": "hasChatAuth" }]
524524
},
525+
{
526+
"name": "appcomposer_deployClicked",
527+
"description": "Called after clicking the Sync button"
528+
},
529+
{
530+
"name": "appcomposer_deployCompleted",
531+
"description": "Called after a Composer-triggered SAM Sync completes"
532+
},
525533
{
526534
"name": "appcomposer_generateClicked",
527535
"description": "Called after generating a standard resource template partial",

0 commit comments

Comments
 (0)