Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not run dependant tasks unless updated services depend on them #429

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ import { mapValues, values, keyBy, omit } from "lodash"
import { Omit } from "./util/util"
import { RuntimeContext } from "./types/service"
import { processServices, ProcessResults } from "./process"
import { getTasksForModule } from "./tasks/helpers"
import { getDependantTasksForModule } from "./tasks/helpers"
import { LogEntry } from "./logger/log-entry"
import { createPluginContext } from "./plugin-context"
import { CleanupEnvironmentParams } from "./types/plugin/params"
Expand Down Expand Up @@ -364,7 +364,7 @@ export class ActionHelper implements TypeGuard {
garden: this.garden,
log,
watch: false,
handler: async (module) => getTasksForModule({
handler: async (module) => getDependantTasksForModule({
garden: this.garden,
log,
module,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
StringsParameter,
} from "./base"
import { hotReloadAndLog, validateHotReloadOpt } from "./helpers"
import { getTasksForModule, getHotReloadModuleNames } from "../tasks/helpers"
import { getDependantTasksForModule, getHotReloadModuleNames } from "../tasks/helpers"
import { TaskResults } from "../task-graph"
import { processServices } from "../process"
import { logHeader } from "../logger/util"
Expand Down Expand Up @@ -108,7 +108,7 @@ export class DeployCommand extends Command<Args, Opts> {
logFooter,
services,
watch,
handler: async (module) => getTasksForModule({
handler: async (module) => getDependantTasksForModule({
garden,
log,
module,
Expand All @@ -121,7 +121,7 @@ export class DeployCommand extends Command<Args, Opts> {
if (hotReloadModuleNames.has(module.name)) {
await hotReloadAndLog(garden, log, module)
}
return getTasksForModule({
return getDependantTasksForModule({
garden, log, module, hotReloadServiceNames, force: true, forceBuild: opts["force-build"],
fromWatch: true, includeDependants: true,
})
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { join } from "path"

import { BaseTask } from "../tasks/base"
import { hotReloadAndLog, validateHotReloadOpt } from "./helpers"
import { getTasksForModule, getHotReloadModuleNames } from "../tasks/helpers"
import { getDependantTasksForModule, getHotReloadModuleNames } from "../tasks/helpers"
import {
Command,
CommandResult,
Expand Down Expand Up @@ -110,7 +110,7 @@ export class DevCommand extends Command<Args, Opts> {
const testTasks: BaseTask[] = flatten(await Bluebird.map(
testModules, m => getTestTasks({ garden, log, module: m })))

return testTasks.concat(await getTasksForModule({
return testTasks.concat(await getDependantTasksForModule({
garden,
log,
module,
Expand Down
16 changes: 4 additions & 12 deletions garden-service/src/tasks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
import { flatten, intersection } from "lodash"
import { DeployTask } from "./deploy"
import { BuildTask } from "./build"
import { TaskTask } from "./task"
import { Garden } from "../garden"
import { Module } from "../types/module"
import { Service } from "../types/service"
import { Task } from "../types/task"
import { DependencyGraphNode } from "../dependency-graph"
import { LogEntry } from "../logger/log-entry"

export async function getTasksForModule(
export async function getDependantTasksForModule(
{ garden, log, module, hotReloadServiceNames, force = false, forceBuild = false,
fromWatch = false, includeDependants = false }:
{
Expand All @@ -29,12 +27,10 @@ export async function getTasksForModule(
let buildTasks: BuildTask[] = []
let dependantBuildModules: Module[] = []
let services: Service[] = []
let tasks: Task[] = []

if (!includeDependants) {
buildTasks.push(new BuildTask({ garden, log, module, force: true, fromWatch, hotReloadServiceNames }))
services = module.services
tasks = module.tasks
} else {
const hotReloadModuleNames = await getHotReloadModuleNames(garden, hotReloadServiceNames)
const dg = await garden.getDependencyGraph()
Expand All @@ -49,13 +45,12 @@ export async function getTasksForModule(

dependantBuildModules = serviceDeps.build
services = serviceDeps.service
tasks = serviceDeps.task
} else {
const dependants = await dg.getDependantsForModule(module, dependantFilterFn)

buildTasks.push(new BuildTask({ garden, log, module, force: true, fromWatch, hotReloadServiceNames }))
dependantBuildModules = dependants.build
services = module.services.concat(dependants.service)
tasks = module.tasks.concat(dependants.task)
}
}

Expand All @@ -65,11 +60,8 @@ export async function getTasksForModule(
const deployTasks = services
.map(service => new DeployTask({ garden, log, service, force, forceBuild, fromWatch, hotReloadServiceNames }))

const taskTasks = tasks
.map(task => new TaskTask({ garden, log, task, force, forceBuild }))

const outputTasks = [...buildTasks, ...deployTasks, ...taskTasks]
log.silly(`getTasksForModule called for module ${module.name}, returning the following tasks:`)
const outputTasks = [...buildTasks, ...deployTasks]
log.silly(`getDependantTasksForModule called for module ${module.name}, returning the following tasks:`)
log.silly(` ${outputTasks.map(t => t.getBaseKey()).join(", ")}`)

return outputTasks
Expand Down
12 changes: 10 additions & 2 deletions garden-service/test/src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("DeployCommand", () => {
const log = garden.log
const command = new DeployCommand()

const { result } = await command.action({
const { result, errors } = await command.action({
garden,
log,
args: {
Expand All @@ -110,6 +110,10 @@ describe("DeployCommand", () => {
},
})

if (errors) {
throw errors[0]
}

expect(taskResultOutputs(result!)).to.eql({
"build.module-a": { fresh: true, buildLog: "A" },
"build.module-b": { fresh: true, buildLog: "B" },
Expand All @@ -131,7 +135,7 @@ describe("DeployCommand", () => {
const log = garden.log
const command = new DeployCommand()

const { result } = await command.action({
const { result, errors } = await command.action({
garden,
log,
args: {
Expand All @@ -145,6 +149,10 @@ describe("DeployCommand", () => {
},
})

if (errors) {
throw errors[0]
}

expect(taskResultOutputs(result!)).to.eql({
"build.module-a": { fresh: true, buildLog: "A" },
"build.module-b": { fresh: true, buildLog: "B" },
Expand Down
Loading