Skip to content

Commit

Permalink
refactor(task-graph): add task key to TaskResult interface
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 committed Dec 11, 2018
1 parent e2c5bbd commit 3ce6633
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions garden-service/src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ export async function processModules(
async (changedModule: Module | null, configChanged: boolean) => {
if (configChanged) {
if (changedModule) {
log.info({ emoji: "gear", section: changedModule.name, msg: `Module configuration changed, reloading...` })
log.info({ section: changedModule.name, msg: `Module configuration changed, reloading...`, symbol: "info" })
} else {
log.info({ emoji: "gear", msg: `Project configuration changed, reloading...` })
log.info({ symbol: "info", msg: `Project configuration changed, reloading...` })
}
resolve()
return
Expand Down
7 changes: 5 additions & 2 deletions garden-service/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class TaskGraphError extends Error { }
export interface TaskResult {
type: string
description: string
key: string
output?: any
dependencyResults?: TaskResults
error?: Error
Expand Down Expand Up @@ -161,7 +162,8 @@ export class TaskGraph {
const type = node.getType()
const baseKey = node.getBaseKey()
const description = node.getDescription()
let result

let result: TaskResult = { type, description, key: task.getKey() }

try {
this.logTask(node)
Expand All @@ -178,7 +180,7 @@ export class TaskGraph {
result = await node.process(dependencyResults)
this.garden.events.emit("taskComplete", result)
} catch (error) {
result = { type, description, error }
result.error = error
this.garden.events.emit("taskError", result)
this.logTaskError(node, error)
await this.cancelDependants(node)
Expand Down Expand Up @@ -423,6 +425,7 @@ class TaskNode {

return {
type: this.getType(),
key: this.getKey(),
description: this.getDescription(),
output,
dependencyResults,
Expand Down
29 changes: 12 additions & 17 deletions garden-service/test/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { makeTestGardenA } from "../../helpers"
import { makeTestGardenA, taskResultOutputs } from "../../helpers"
import { startServer } from "../../../src/server/server"
import { Server } from "http"
import { Garden } from "../../../src/garden"
Expand Down Expand Up @@ -64,15 +64,10 @@ describe("startServer", () => {
},
}).expect(200)

expect(res.body.result).to.eql({
expect(taskResultOutputs(res.body.result)).to.eql({
"build.module-a": {
dependencyResults: {},
description: "building module-a",
output: {
buildLog: "A",
fresh: true,
},
type: "build",
buildLog: "A",
fresh: true,
},
})
})
Expand Down Expand Up @@ -167,18 +162,18 @@ describe("startServer", () => {
it("should correctly map arguments and options to commands", (done) => {
const id = uuid.v4()
onMessage((req) => {
expect(req).to.eql({
const taskResult = taskResultOutputs((<any>req).result)
const result = {
...req,
result: taskResult,
}
expect(result).to.eql({
type: "commandResult",
requestId: id,
result: {
"build.module-a": {
dependencyResults: {},
description: "building module-a",
output: {
buildLog: "A",
fresh: true,
},
type: "build",
buildLog: "A",
fresh: true,
},
},
})
Expand Down
6 changes: 6 additions & 0 deletions garden-service/test/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe("task-graph", () => {
a: {
type: "test",
description: "a",
key: "a",
output: {
result: "result-a",
dependencyResults: {},
Expand Down Expand Up @@ -233,6 +234,7 @@ describe("task-graph", () => {
const resultA: TaskResult = {
type: "test",
description: "a.a1",
key: "a.a1",
output: {
result: "result-a.a1",
dependencyResults: {},
Expand All @@ -241,6 +243,7 @@ describe("task-graph", () => {
}
const resultB: TaskResult = {
type: "test",
key: "b.b1",
description: "b.b1",
output: {
result: "result-b.b1",
Expand All @@ -251,6 +254,7 @@ describe("task-graph", () => {
const resultC: TaskResult = {
type: "test",
description: "c.c1",
key: "c.c1",
output: {
result: "result-c.c1",
dependencyResults: { b: resultB },
Expand All @@ -265,6 +269,7 @@ describe("task-graph", () => {
d: {
type: "test",
description: "d.d1",
key: "d.d1",
output: {
result: "result-d.d1",
dependencyResults: {
Expand Down Expand Up @@ -326,6 +331,7 @@ describe("task-graph", () => {
const resultA: TaskResult = {
type: "test",
description: "a",
key: "a.a1",
output: {
result: "result-a",
dependencyResults: {},
Expand Down

0 comments on commit 3ce6633

Please sign in to comment.