Skip to content

Commit

Permalink
fix: checking cancellation token during pack and any retry tasks to e…
Browse files Browse the repository at this point in the history
…xit early on process "cancel" (#8375)
  • Loading branch information
mmaietta authored Jul 23, 2024
1 parent 30bce62 commit 54c1059
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/silly-impalas-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"builder-util": patch
---

fix: checking cancellation token during pack and any retry tasks to exit early on process "cancel"
14 changes: 14 additions & 0 deletions packages/app-builder-lib/src/macPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,19 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
const x64Arch = Arch.x64
const x64AppOutDir = outDirName(x64Arch)
await super.doPack(outDir, x64AppOutDir, platformName, x64Arch, platformSpecificBuildOptions, targets, false, true)

if (this.info.cancellationToken.cancelled) {
return
}

const arm64Arch = Arch.arm64
const arm64AppOutPath = outDirName(arm64Arch)
await super.doPack(outDir, arm64AppOutPath, platformName, arm64Arch, platformSpecificBuildOptions, targets, false, true)

if (this.info.cancellationToken.cancelled) {
return
}

const framework = this.info.framework
log.info(
{
Expand Down Expand Up @@ -163,6 +173,10 @@ export class MacPackager extends PlatformPackager<MacConfiguration> {
}
await this.info.afterPack(packContext)

if (this.info.cancellationToken.cancelled) {
return
}

await this.doSignAfterPack(outDir, appOutDir, platformName, arch, platformSpecificBuildOptions, targets)
break
}
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/platformPackager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
await subTaskManager.awaitTasks()

for (const target of targets) {
if (!target.isAsyncSupported) {
if (!target.isAsyncSupported && !this.info.cancellationToken.cancelled) {
await target.build(appOutDir, arch)
}
}
Expand Down
5 changes: 3 additions & 2 deletions packages/builder-util/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { appBuilderPath } from "app-builder-bin"
import { safeStringifyJson } from "builder-util-runtime"
import { CancellationToken, safeStringifyJson } from "builder-util-runtime"
import * as chalk from "chalk"
import { ChildProcess, execFile, ExecFileOptions, SpawnOptions } from "child_process"
import { spawn as _spawn } from "cross-spawn"
Expand Down Expand Up @@ -408,11 +408,12 @@ export async function executeAppBuilder(
}

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

0 comments on commit 54c1059

Please sign in to comment.