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

Simulate file access #789

Merged
merged 12 commits into from
Sep 27, 2024
4 changes: 3 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const path = require("path");

// This is only used to enable eslint in the editor
module.exports = {
...require("./scripts/config/eslintrc"),
parserOptions: {
project: "./scripts/config/tsconfig.eslint.json",
project: path.join(__dirname, "./scripts/config/tsconfig.eslint.json"),
},
ignorePatterns: ["**/*.js", "**/__fixtures__", "**/hasher/src/__tests__", "docs", "packages/*/scripts", "packages/*/src/gen", "lib/"],
};
39 changes: 39 additions & 0 deletions change/change-82487442-ab6c-4773-9770-15dca576410d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"changes": [
{
"type": "minor",
"comment": "Simulate file access for lage server",
"packageName": "@lage-run/cli",
"email": "[email protected]",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "packages into a bundled globby types",
"packageName": "@lage-run/globby",
"email": "[email protected]",
"dependentChangeType": "patch"
},
{
"type": "minor",
"comment": "exposes getInputFiles, packageTrees",
"packageName": "@lage-run/hasher",
"email": "[email protected]",
"dependentChangeType": "patch"
},
{
"type": "patch",
"comment": "Simulate file access for lage server",
"packageName": "@lage-run/rpc",
"email": "[email protected]",
"dependentChangeType": "patch"
},
{
"type": "patch",
"comment": "Simulate file access for lage server",
"packageName": "@lage-run/scheduler",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
11 changes: 11 additions & 0 deletions change/change-dcbd2f5c-b20e-448d-8579-a660a87102ad.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "adds an idle event emit",
"packageName": "@lage-run/worker-threads-pool",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
11 changes: 8 additions & 3 deletions lage.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ module.exports = {
type: "noop",
dependsOn: ["transpile", "types"],
},
"@lage-run/globby#build": {
"@lage-run/globby#types": {
type: "npmScript",
dependsOn: ["types"],
},
"@lage-run/globby#transpile": {
type: "noop",
type: "npmScript",
},
"@lage-run/globby#isoldatedTypes": {
type: "npmScript",
options: {
script: "types",
},
},
lint: {
type: "worker",
Expand Down
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dependencies": {
"@lage-run/cache": "^1.3.3",
"@lage-run/config": "^0.4.2",
"@lage-run/globby": "^14.0.3",
"@lage-run/hasher": "^1.4.0",
"@lage-run/logger": "^1.3.1",
"@lage-run/reporters": "^1.2.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/run/createTargetGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CreateTargetGraphOptions {
dependencies: boolean;
dependents: boolean;
since: string;
scope: string[];
scope?: string[];
ignore: string[];
repoWideChanges: string[];
pipeline: PipelineDefinition;
Expand Down
37 changes: 26 additions & 11 deletions packages/cli/src/commands/server/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type { Command } from "commander";
import type { LageClient } from "@lage-run/rpc";
import { filterArgsForTasks } from "../run/filterArgsForTasks.js";
import { ConnectError, createClient, createServer } from "@lage-run/rpc";
import { simulateFileAccess } from "./simulateFileAccess.js";

interface WorkerOptions extends ReporterInitOptions {
nodeArg?: string[];
Expand Down Expand Up @@ -53,9 +54,15 @@ async function executeOnServer(args: string[], client: LageClient, logger: Logge
taskArgs,
});

logger.info(`Task ${response.packageName} #${response.task} exited with code ${response.exitCode} `);
logger.info(`Task ${response.packageName} ${response.task} exited with code ${response.exitCode} `);

process.exitCode = response.exitCode;

if (response.exitCode === 0) {
await simulateFileAccess(logger, response.inputs, response.outputs);
}

logger.info("Task execution finished");
}

export async function serverAction(options: WorkerOptions, command: Command) {
Expand All @@ -78,13 +85,17 @@ export async function serverAction(options: WorkerOptions, command: Command) {

const abortController = new AbortController();

const lageService = await createLageService(process.cwd(), abortController, logger, options.concurrency);
const server = await createServer(lageService, abortController);

server.addHook("onRequest", (req, res, next) => {
resetTimer(logger, timeout, abortController, server);
next();
const lageService = await createLageService({
cwd: process.cwd(),
serverControls: {
abortController,
countdownToShutdown: () => resetTimer(logger, timeout, abortController, server),
clearCountdown: clearTimer,
},
logger,
maxWorkers: options.concurrency,
});
const server = await createServer(lageService, abortController);

await server.listen({ host, port });
logger.info(`Server listening on http://${host}:${port}, timeout in ${timeout} seconds`);
Expand All @@ -102,13 +113,17 @@ export async function serverAction(options: WorkerOptions, command: Command) {

let timeoutHandle: NodeJS.Timeout | undefined;
function resetTimer(logger: Logger, timeout: number, abortController: AbortController, server: any) {
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
clearTimer();

timeoutHandle = setTimeout(() => {
timeoutHandle = globalThis.setTimeout(() => {
logger.info(`Server timed out after ${timeout} seconds`);
abortController.abort();
server.close();
}, timeout * 1000);
}

function clearTimer() {
if (timeoutHandle) {
globalThis.clearTimeout(timeoutHandle);
}
}
38 changes: 0 additions & 38 deletions packages/cli/src/commands/server/executeRemotely.ts

This file was deleted.

17 changes: 17 additions & 0 deletions packages/cli/src/commands/server/getOutputFiles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { CacheOptions } from "@lage-run/config";
import { glob } from "@lage-run/globby";
import type { PackageTree } from "@lage-run/hasher";
import type { Target } from "@lage-run/target-graph";

import path from "path";

export function getOutputFiles(root: string, target: Target, outputGlob: CacheOptions["outputGlob"], packageTree: PackageTree) {
const patterns = target.outputs ?? outputGlob ?? ["**/*"];

const sourceControlledFiles = new Set(packageTree.getPackageFiles(target.packageName ?? "", patterns));
const outputs = glob(patterns, { cwd: target.cwd, gitignore: false })
.map((file) => path.relative(root, path.join(target.cwd, file)))
.filter((file) => !sourceControlledFiles.has(file));

return outputs;
}
Loading
Loading