-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(build): fix intermittent concurrency issues when staging build
Because both the BuildTask and GetServiceTask need to stage builds, they could in some cases end up stepping on each other because one doesn't depend on the other. I resolved that by adding a StageBuildTask that both depend on.
- Loading branch information
Showing
12 changed files
with
188 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import Bluebird from "bluebird" | ||
import chalk from "chalk" | ||
import pluralize from "pluralize" | ||
import { Module, getModuleKey } from "../types/module" | ||
import { BuildResult } from "../types/plugin/module/build" | ||
import { BaseTask, TaskType } from "../tasks/base" | ||
import { Garden } from "../garden" | ||
import { LogEntry } from "../logger/log-entry" | ||
|
||
export interface StageBuildTaskParams { | ||
garden: Garden | ||
log: LogEntry | ||
module: Module | ||
force: boolean | ||
} | ||
|
||
export class StageBuildTask extends BaseTask { | ||
type: TaskType = "stage-build" | ||
|
||
private module: Module | ||
|
||
constructor({ garden, log, module, force }: StageBuildTaskParams) { | ||
super({ garden, log, force, version: module.version }) | ||
this.module = module | ||
} | ||
|
||
async getDependencies() { | ||
const dg = await this.garden.getConfigGraph() | ||
const deps = (await dg.getDependencies("build", this.getName(), false)).build | ||
|
||
return Bluebird.map(deps, async (m: Module) => { | ||
return new StageBuildTask({ | ||
garden: this.garden, | ||
log: this.log, | ||
module: m, | ||
force: this.force, | ||
}) | ||
}) | ||
} | ||
|
||
getName() { | ||
return getModuleKey(this.module.name, this.module.plugin) | ||
} | ||
|
||
getDescription() { | ||
return `staging build for ${this.getName()}` | ||
} | ||
|
||
async process(): Promise<BuildResult> { | ||
let log: LogEntry | undefined = undefined | ||
|
||
if (this.module.version.files.length > 0) { | ||
log = this.log.info({ | ||
section: this.getName(), | ||
msg: `Syncing module sources (${pluralize("file", this.module.version.files.length, true)})...`, | ||
status: "active", | ||
}) | ||
} | ||
|
||
const graph = await this.garden.getConfigGraph() | ||
await this.garden.buildDir.syncFromSrc(this.module, log || this.log) | ||
await this.garden.buildDir.syncDependencyProducts(this.module, graph, log || this.log) | ||
|
||
if (log) { | ||
log.setSuccess({ | ||
msg: chalk.green(`Done (took ${log.getDuration(1)} sec)`), | ||
append: true, | ||
}) | ||
} | ||
|
||
return {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.