Skip to content

Commit 54c1059

Browse files
authoredJul 23, 2024··
fix: checking cancellation token during pack and any retry tasks to exit early on process "cancel" (#8375)
1 parent 30bce62 commit 54c1059

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed
 

‎.changeset/silly-impalas-relax.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"app-builder-lib": patch
3+
"builder-util": patch
4+
---
5+
6+
fix: checking cancellation token during pack and any retry tasks to exit early on process "cancel"

‎packages/app-builder-lib/src/macPackager.ts

+14
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,19 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
125125
const x64Arch = Arch.x64
126126
const x64AppOutDir = outDirName(x64Arch)
127127
await super.doPack(outDir, x64AppOutDir, platformName, x64Arch, platformSpecificBuildOptions, targets, false, true)
128+
129+
if (this.info.cancellationToken.cancelled) {
130+
return
131+
}
132+
128133
const arm64Arch = Arch.arm64
129134
const arm64AppOutPath = outDirName(arm64Arch)
130135
await super.doPack(outDir, arm64AppOutPath, platformName, arm64Arch, platformSpecificBuildOptions, targets, false, true)
136+
137+
if (this.info.cancellationToken.cancelled) {
138+
return
139+
}
140+
131141
const framework = this.info.framework
132142
log.info(
133143
{
@@ -163,6 +173,10 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
163173
}
164174
await this.info.afterPack(packContext)
165175

176+
if (this.info.cancellationToken.cancelled) {
177+
return
178+
}
179+
166180
await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets)
167181
break
168182
}

‎packages/app-builder-lib/src/platformPackager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
152152
await subTaskManager.awaitTasks()
153153

154154
for (const target of targets) {
155-
if (!target.isAsyncSupported) {
155+
if (!target.isAsyncSupported && !this.info.cancellationToken.cancelled) {
156156
await target.build(appOutDir, arch)
157157
}
158158
}

‎packages/builder-util/src/util.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { appBuilderPath } from "app-builder-bin"
2-
import { safeStringifyJson } from "builder-util-runtime"
2+
import { CancellationToken, safeStringifyJson } from "builder-util-runtime"
33
import * as chalk from "chalk"
44
import { ChildProcess, execFile, ExecFileOptions, SpawnOptions } from "child_process"
55
import { spawn as _spawn } from "cross-spawn"
@@ -408,11 +408,12 @@ export async function executeAppBuilder(
408408
}
409409

410410
export async function retry<T>(task: () => Promise<T>, retryCount: number, interval: number, backoff = 0, attempt = 0, shouldRetry?: (e: any) => boolean): Promise<T> {
411+
const cancellationToken = new CancellationToken()
411412
try {
412413
return await task()
413414
} catch (error: any) {
414415
log.info(`Above command failed, retrying ${retryCount} more times`)
415-
if ((shouldRetry?.(error) ?? true) && retryCount > 0) {
416+
if ((shouldRetry?.(error) ?? true) && retryCount > 0 && !cancellationToken.cancelled) {
416417
await new Promise(resolve => setTimeout(resolve, interval + backoff * attempt))
417418
return await retry(task, retryCount - 1, interval, backoff, attempt + 1, shouldRetry)
418419
} else {

0 commit comments

Comments
 (0)
Please sign in to comment.