Skip to content

Commit

Permalink
refactor: rename Task to BaseTask
Browse files Browse the repository at this point in the history
  • Loading branch information
thsig committed Nov 20, 2018
1 parent 7f65c9a commit 9b40291
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions garden-service/src/commands/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import moment = require("moment")
import { join } from "path"

import { BuildTask } from "../tasks/build"
import { Task } from "../tasks/base"
import { BaseTask } from "../tasks/base"
import { hotReloadAndLog, validateHotReloadOpt } from "./helpers"
import { getTasksForModule, getHotReloadModuleNames } from "../tasks/helpers"
import {
Expand Down Expand Up @@ -101,7 +101,7 @@ export class DevCommand extends Command<Args, Opts> {
? (await dependencyGraph.withDependantModules([module]))
: [module]

const testTasks: Task[] = flatten(await Bluebird.map(
const testTasks: BaseTask[] = flatten(await Bluebird.map(
testModules, m => getTestTasks({ garden, module: m })))

const tasks = testTasks.concat(await getTasksForModule({
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ import {
loadConfig,
findProjectConfig,
} from "./config/base"
import { Task } from "./tasks/base"
import { BaseTask } from "./tasks/base"
import { LocalConfigStore } from "./config-store"
import { detectCircularDependencies } from "./util/detectCycles"
import {
Expand Down Expand Up @@ -337,7 +337,7 @@ export class Garden {
return this.buildDir.clear()
}

async addTask(task: Task) {
async addTask(task: BaseTask) {
await this.taskGraph.addTask(task)
}

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import Bluebird = require("bluebird")
import chalk from "chalk"
import { Module } from "./types/module"
import { Service } from "./types/service"
import { Task } from "./tasks/base"
import { BaseTask } from "./tasks/base"
import { TaskResults } from "./task-graph"
import { FSWatcher } from "./watch"
import { registerCleanupFunction } from "./util/util"
import { isModuleLinked } from "./util/ext-source-util"
import { Garden } from "./garden"

export type ProcessHandler = (module: Module) => Promise<Task[]>
export type ProcessHandler = (module: Module) => Promise<BaseTask[]>

interface ProcessParams {
garden: Garden,
Expand Down
18 changes: 9 additions & 9 deletions garden-service/src/task-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as Bluebird from "bluebird"
import * as PQueue from "p-queue"
import chalk from "chalk"
import { merge, padEnd, pick } from "lodash"
import { Task, TaskDefinitionError } from "./tasks/base"
import { BaseTask, TaskDefinitionError } from "./tasks/base"

import { LogEntry } from "./logger/log-entry"
import { toGardenError } from "./exceptions"
Expand Down Expand Up @@ -55,15 +55,15 @@ export class TaskGraph {
this.logEntryMap = {}
}

async addTask(task: Task): Promise<void> {
async addTask(task: BaseTask): Promise<void> {
return this.opQueue.add(() => this.addTaskInternal(task))
}

async processTasks(): Promise<TaskResults> {
return this.opQueue.add(() => this.processTasksInternal())
}

private async addTaskInternal(task: Task) {
private async addTaskInternal(task: BaseTask) {
const predecessor = this.getPredecessor(task)
let node = this.getNode(task)

Expand Down Expand Up @@ -97,7 +97,7 @@ export class TaskGraph {
}
}

private getNode(task: Task): TaskNode {
private getNode(task: BaseTask): TaskNode {
const existing = this.index.getNode(task)
return existing || new TaskNode(task)
}
Expand Down Expand Up @@ -181,7 +181,7 @@ export class TaskGraph {
this.logTaskComplete(node, success)
}

private getPredecessor(task: Task): TaskNode | null {
private getPredecessor(task: BaseTask): TaskNode | null {
const key = task.getKey()
const baseKey = task.getBaseKey()
const predecessors = this.index.getNodes()
Expand Down Expand Up @@ -292,7 +292,7 @@ export class TaskGraph {
}
}

function getIndexKey(task: Task) {
function getIndexKey(task: BaseTask) {
const key = task.getKey()

if (!task.type || !key || task.type.length === 0 || key.length === 0) {
Expand All @@ -312,7 +312,7 @@ class TaskNodeMap {
this.length = 0
}

getNode(task: Task) {
getNode(task: BaseTask) {
const indexKey = getIndexKey(task)
const element = this.index.get(indexKey)
return element
Expand Down Expand Up @@ -344,12 +344,12 @@ class TaskNodeMap {
}

class TaskNode {
task: Task
task: BaseTask

private dependencies: TaskNodeMap
private dependants: TaskNodeMap

constructor(task: Task) {
constructor(task: BaseTask) {
this.task = task
this.dependencies = new TaskNodeMap()
this.dependants = new TaskNodeMap()
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/tasks/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ export interface TaskParams {
version: ModuleVersion
}

export abstract class Task {
export abstract class BaseTask {
abstract type: string
abstract depType: DependencyGraphNodeType
garden: Garden
id: string
force: boolean
version: ModuleVersion

dependencies: Task[]
dependencies: BaseTask[]

constructor(initArgs: TaskParams) {
this.garden = initArgs.garden
Expand All @@ -38,7 +38,7 @@ export abstract class Task {
this.version = initArgs.version
}

async getDependencies(): Promise<Task[]> {
async getDependencies(): Promise<BaseTask[]> {
return this.dependencies
}

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/tasks/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as Bluebird from "bluebird"
import chalk from "chalk"
import { Module, getModuleKey } from "../types/module"
import { BuildResult } from "../types/plugin/outputs"
import { Task } from "../tasks/base"
import { BaseTask } from "../tasks/base"
import { Garden } from "../garden"
import { DependencyGraphNodeType } from "../dependency-graph"
import { getHotReloadModuleNames } from "./helpers"
Expand All @@ -23,7 +23,7 @@ export interface BuildTaskParams {
hotReloadServiceNames?: string[]
}

export class BuildTask extends Task {
export class BuildTask extends BaseTask {
type = "build"
depType: DependencyGraphNodeType = "build"

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import * as Bluebird from "bluebird"
import chalk from "chalk"
import { includes } from "lodash"
import { LogEntry } from "../logger/log-entry"
import { Task } from "./base"
import { BaseTask } from "./base"
import {
Service,
ServiceStatus,
Expand All @@ -32,7 +32,7 @@ export interface DeployTaskParams {
hotReloadServiceNames?: string[]
}

export class DeployTask extends Task {
export class DeployTask extends BaseTask {
type = "deploy"
depType: DependencyGraphNodeType = "service"

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/tasks/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import chalk from "chalk"
import { BuildTask } from "./build"
import { Module } from "../types/module"
import { PublishResult } from "../types/plugin/outputs"
import { Task } from "../tasks/base"
import { BaseTask } from "../tasks/base"
import { Garden } from "../garden"
import { DependencyGraphNodeType } from "../dependency-graph"

Expand All @@ -20,7 +20,7 @@ export interface PublishTaskParams {
forceBuild: boolean
}

export class PublishTask extends Task {
export class PublishTask extends BaseTask {
type = "publish"
depType: DependencyGraphNodeType = "publish"

Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/tasks/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import chalk from "chalk"
import { BuildTask } from "./build"
import { Module } from "../types/module"
import { PushResult } from "../types/plugin/outputs"
import { Task } from "../tasks/base"
import { BaseTask } from "../tasks/base"
import { Garden } from "../garden"
import { DependencyGraphNodeType } from "../dependency-graph"

Expand All @@ -22,7 +22,7 @@ export interface PushTaskParams {
hotReloadServiceNames?: string[]
}

export class PushTask extends Task {
export class PushTask extends BaseTask {
type = "push"
depType: DependencyGraphNodeType = "push"

Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/tasks/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ModuleVersion } from "../vcs/base"
import { BuildTask } from "./build"
import { DeployTask } from "./deploy"
import { TestResult } from "../types/plugin/outputs"
import { Task, TaskParams } from "../tasks/base"
import { BaseTask, TaskParams } from "../tasks/base"
import { prepareRuntimeContext } from "../types/service"
import { Garden } from "../garden"
import { DependencyGraphNodeType } from "../dependency-graph"
Expand All @@ -33,7 +33,7 @@ export interface TestTaskParams {
forceBuild: boolean
}

export class TestTask extends Task {
export class TestTask extends BaseTask {
type = "test"
depType: DependencyGraphNodeType = "test"

Expand Down Expand Up @@ -65,7 +65,7 @@ export class TestTask extends Task {
const dg = await this.garden.getDependencyGraph()
const services = (await dg.getDependencies(this.depType, this.getName(), false)).service

const deps: Task[] = [new BuildTask({
const deps: BaseTask[] = [new BuildTask({
garden: this.garden,
module: this.module,
force: this.forceBuild,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/tasks/workflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

import chalk from "chalk"
import { Task } from "../tasks/base"
import { BaseTask } from "../tasks/base"
import { Garden } from "../garden"
import { Workflow } from "../types/workflow"
import { BuildTask } from "./build"
Expand All @@ -25,7 +25,7 @@ export interface WorkflowTaskParams {
logEntry?: LogEntry
}

export class WorkflowTask extends Task {
export class WorkflowTask extends BaseTask {
type = "workflow"
depType: DependencyGraphNodeType = "workflow"

Expand All @@ -38,7 +38,7 @@ export class WorkflowTask extends Task {
this.forceBuild = forceBuild
}

async getDependencies(): Promise<Task[]> {
async getDependencies(): Promise<BaseTask[]> {

const buildTask = new BuildTask({
garden: this.garden,
Expand Down
6 changes: 3 additions & 3 deletions garden-service/test/src/task-graph.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from "path"
import { expect } from "chai"
import { Task } from "../../src/tasks/base"
import { BaseTask } from "../../src/tasks/base"
import {
TaskGraph,
TaskResult,
Expand All @@ -20,7 +20,7 @@ interface TestTaskOptions {
throwError?: boolean
}

class TestTask extends Task {
class TestTask extends BaseTask {
type = "test"
depType: DependencyGraphNodeType = "test"
name: string
Expand All @@ -31,7 +31,7 @@ class TestTask extends Task {
constructor(
garden: Garden,
name: string,
dependencies?: Task[],
dependencies?: BaseTask[],
options?: TestTaskOptions,
) {
super({
Expand Down
6 changes: 3 additions & 3 deletions garden-service/test/src/tasks/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { resolve } from "path"
import { Garden } from "../../../src/garden"
import { makeTestGarden, dataDir } from "../../helpers"
import { getTasksForModule } from "../../../src/tasks/helpers"
import { Task } from "../../../src/tasks/base"
import { BaseTask } from "../../../src/tasks/base"

async function sortedBaseKeysWithDependencies(tasks: Task[]): Promise<string[]> {
async function sortedBaseKeysWithDependencies(tasks: BaseTask[]): Promise<string[]> {
return sortedBaseKeys(flatten([tasks].concat(await Bluebird.map(tasks, t => t.getDependencies()))))
}

function sortedBaseKeys(tasks: Task[]): string[] {
function sortedBaseKeys(tasks: BaseTask[]): string[] {
return uniq(tasks.map(t => t.getBaseKey())).sort()
}

Expand Down

0 comments on commit 9b40291

Please sign in to comment.