-
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: Added OperationQueue to TaskGraph.
- Loading branch information
Showing
16 changed files
with
258 additions
and
150 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
/* | ||
* 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 { keys, values } from "lodash" | ||
import { Command } from "./base" | ||
import { Module } from "../types/module" | ||
import { GardenContext } from "../context" | ||
import { FSWatcher } from "../fs-watcher" | ||
import { PluginContext } from "../plugin-context" | ||
import { BuildTask } from "../tasks/build" | ||
import { DeployTask } from "../tasks/deploy" | ||
import { registerCleanupFunction, sleep } from "../util" | ||
|
||
export type AutoReloadDependants = { [key: string]: Set<Module> } | ||
|
||
async function registerAutoReloadWatches(ctx: GardenContext): Promise<FSWatcher | null> { | ||
async function registerAutoReloadWatches(ctx: PluginContext): Promise<FSWatcher | null> { | ||
const allModules = values(await ctx.getModules()) | ||
const modules = allModules.filter((m) => !m.skipAutoReload) | ||
|
||
|
@@ -25,7 +33,7 @@ async function registerAutoReloadWatches(ctx: GardenContext): Promise<FSWatcher | |
|
||
const autoReloadDependants = await computeAutoReloadDependants(modules) | ||
|
||
const watcher = new FSWatcher(ctx) | ||
const watcher = new FSWatcher(ctx.projectRoot) | ||
watcher.watchModules(modules, "addTasksForAutoReload/", | ||
async (changedModule, _) => { | ||
ctx.log.info({ msg: `files changed for module ${changedModule.name}` }) | ||
|
@@ -50,7 +58,7 @@ export async function computeAutoReloadDependants(modules: Module[]): | |
return dependants | ||
} | ||
|
||
export async function addTasksForAutoReload(ctx: GardenContext, module: Module, dependants: AutoReloadDependants) { | ||
export async function addTasksForAutoReload(ctx: PluginContext, module: Module, dependants: AutoReloadDependants) { | ||
const serviceNames = keys(module.services || {}) | ||
|
||
if (serviceNames.length === 0) { | ||
|
@@ -74,7 +82,7 @@ export class AutoReloadCommand extends Command { | |
name = "autoreload" | ||
help = "Auto-reload modules when sources change" | ||
|
||
async action(ctx: GardenContext): Promise<void> { | ||
async action(ctx: PluginContext): Promise<void> { | ||
const watcher = await registerAutoReloadWatches(ctx) | ||
|
||
if (!watcher) { | ||
|
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 |
---|---|---|
@@ -1,9 +1,16 @@ | ||
/* | ||
* 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 { map as bluebirdMap } from "bluebird" | ||
import { Client } from "fb-watchman" | ||
import { keyBy } from "lodash" | ||
import { resolve } from "path" | ||
import { Module } from "./types/module" | ||
import { GardenContext } from "./context" | ||
|
||
export type CapabilityOptions = { required?: string[], optional?: string[] } | ||
export type CapabilityResponse = { error: Error, response: { capabilities: { string: boolean } } } | ||
|
@@ -22,12 +29,10 @@ export type SubscriptionResponse = { | |
} | ||
|
||
export class FSWatcher { | ||
readonly ctx: GardenContext | ||
private readonly client | ||
private capabilityCheckComplete: boolean | ||
|
||
constructor(ctx: GardenContext) { | ||
this.ctx = ctx | ||
constructor(private projectRoot: string) { | ||
this.client = new Client() | ||
this.capabilityCheckComplete = false | ||
} | ||
|
@@ -53,6 +58,7 @@ export class FSWatcher { | |
}) | ||
} | ||
|
||
// WIP | ||
async watchModules(modules: Module[], subscriptionPrefix: string, | ||
changeHandler: (Module, SubscriptionResponse) => Promise<void>) { | ||
if (!this.capabilityCheckComplete) { | ||
|
@@ -63,10 +69,17 @@ export class FSWatcher { | |
|
||
await bluebirdMap(modules || [], async (module) => { | ||
const subscriptionKey = FSWatcher.subscriptionKey(subscriptionPrefix, module) | ||
const modulePath = resolve(this.ctx.projectRoot, module.path) | ||
const modulePath = resolve(this.projectRoot, module.path) | ||
|
||
const result = await this.command(["watch-project", modulePath]) | ||
|
||
const subscriptionRequest = {} | ||
// console.log("watching", modulePath) | ||
|
||
const subscriptionRequest = { | ||
// expression: ["anyof", | ||
// ["dirname", modulePath, ["depth", "ge", 0]] | ||
// ] | ||
} | ||
|
||
await this.command([ | ||
"subscribe", | ||
|
@@ -76,7 +89,7 @@ export class FSWatcher { | |
}) | ||
|
||
this.on("subscription", async (response) => { | ||
console.log("file changed:", response) | ||
// console.log("file changed:", response) | ||
const changedModule = modulesBySubscriptionKey[response.subscription] | ||
if (!changedModule) { | ||
console.log("no module found for changed file, skipping auto-rebuild") | ||
|
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 |
---|---|---|
@@ -1,3 +1,11 @@ | ||
/* | ||
* 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 { TaskResults } from "../task-graph" | ||
import { v1 as uuidv1 } from "uuid" | ||
|
||
|
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.