@lage-run/scheduler 1.2.7 → 1.2.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +49 -1
- package/CHANGELOG.md +21 -2
- package/lib/SimpleScheduler.d.ts +2 -2
- package/lib/SimpleScheduler.js +2 -2
- package/lib/index.d.ts +0 -4
- package/lib/index.js +3 -24
- package/lib/workers/targetWorker.js +2 -2
- package/package.json +5 -4
- package/lib/runners/NoOpRunner.d.ts +0 -5
- package/lib/runners/NoOpRunner.js +0 -18
- package/lib/runners/NpmScriptRunner.d.ts +0 -34
- package/lib/runners/NpmScriptRunner.js +0 -145
- package/lib/runners/TargetRunnerPicker.d.ts +0 -7
- package/lib/runners/TargetRunnerPicker.js +0 -59
- package/lib/runners/WorkerRunner.d.ts +0 -48
- package/lib/runners/WorkerRunner.js +0 -64
package/CHANGELOG.json
CHANGED
|
@@ -2,7 +2,55 @@
|
|
|
2
2
|
"name": "@lage-run/scheduler",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
|
-
"date": "
|
|
5
|
+
"date": "Fri, 30 Aug 2024 18:39:54 GMT",
|
|
6
|
+
"version": "1.2.9",
|
|
7
|
+
"tag": "@lage-run/scheduler_v1.2.9",
|
|
8
|
+
"comments": {
|
|
9
|
+
"patch": [
|
|
10
|
+
{
|
|
11
|
+
"author": "beachball",
|
|
12
|
+
"package": "@lage-run/scheduler",
|
|
13
|
+
"comment": "Bump @lage-run/hasher to v1.3.0",
|
|
14
|
+
"commit": "not available"
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"date": "Wed, 28 Aug 2024 21:12:45 GMT",
|
|
21
|
+
"version": "1.2.8",
|
|
22
|
+
"tag": "@lage-run/scheduler_v1.2.8",
|
|
23
|
+
"comments": {
|
|
24
|
+
"patch": [
|
|
25
|
+
{
|
|
26
|
+
"author": "kchau@microsoft.com",
|
|
27
|
+
"package": "@lage-run/scheduler",
|
|
28
|
+
"commit": "8b27a04b8d5916457d1c8219edd1f2d216543954",
|
|
29
|
+
"comment": "moving runners to its own package, fixing up imports"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"author": "beachball",
|
|
33
|
+
"package": "@lage-run/scheduler",
|
|
34
|
+
"comment": "Bump @lage-run/config to v0.3.7",
|
|
35
|
+
"commit": "not available"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"author": "beachball",
|
|
39
|
+
"package": "@lage-run/scheduler",
|
|
40
|
+
"comment": "Bump @lage-run/runners to v1.0.1",
|
|
41
|
+
"commit": "not available"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"author": "beachball",
|
|
45
|
+
"package": "@lage-run/scheduler",
|
|
46
|
+
"comment": "Bump @lage-run/scheduler-types to v0.3.14",
|
|
47
|
+
"commit": "not available"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"date": "Tue, 25 Jun 2024 22:03:40 GMT",
|
|
6
54
|
"version": "1.2.7",
|
|
7
55
|
"tag": "@lage-run/scheduler_v1.2.7",
|
|
8
56
|
"comments": {
|
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,31 @@
|
|
|
1
1
|
# Change Log - @lage-run/scheduler
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Fri, 30 Aug 2024 18:39:54 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 1.2.9
|
|
8
|
+
|
|
9
|
+
Fri, 30 Aug 2024 18:39:54 GMT
|
|
10
|
+
|
|
11
|
+
### Patches
|
|
12
|
+
|
|
13
|
+
- Bump @lage-run/hasher to v1.3.0
|
|
14
|
+
|
|
15
|
+
## 1.2.8
|
|
16
|
+
|
|
17
|
+
Wed, 28 Aug 2024 21:12:45 GMT
|
|
18
|
+
|
|
19
|
+
### Patches
|
|
20
|
+
|
|
21
|
+
- moving runners to its own package, fixing up imports (kchau@microsoft.com)
|
|
22
|
+
- Bump @lage-run/config to v0.3.7
|
|
23
|
+
- Bump @lage-run/runners to v1.0.1
|
|
24
|
+
- Bump @lage-run/scheduler-types to v0.3.14
|
|
25
|
+
|
|
7
26
|
## 1.2.7
|
|
8
27
|
|
|
9
|
-
Tue, 25 Jun 2024 22:03:
|
|
28
|
+
Tue, 25 Jun 2024 22:03:40 GMT
|
|
10
29
|
|
|
11
30
|
### Patches
|
|
12
31
|
|
package/lib/SimpleScheduler.d.ts
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
/// <reference types="global" />
|
|
4
4
|
import { WrappedTarget } from "./WrappedTarget.js";
|
|
5
|
-
import { TargetRunnerPicker } from "
|
|
5
|
+
import { TargetRunnerPicker } from "@lage-run/runners";
|
|
6
6
|
import type { WorkerResult } from "./WrappedTarget.js";
|
|
7
7
|
import type { Logger } from "@lage-run/logger";
|
|
8
8
|
import type { TargetGraph } from "@lage-run/target-graph";
|
|
9
9
|
import type { TargetScheduler, SchedulerRunSummary } from "@lage-run/scheduler-types";
|
|
10
10
|
import type { Pool } from "@lage-run/worker-threads-pool";
|
|
11
|
-
import type { TargetRunnerPickerOptions } from "@lage-run/
|
|
11
|
+
import type { TargetRunnerPickerOptions } from "@lage-run/runners";
|
|
12
12
|
import type { TargetHasher } from "@lage-run/hasher";
|
|
13
13
|
import type { CacheOptions } from "@lage-run/cache";
|
|
14
14
|
import type { MessagePort } from "worker_threads";
|
package/lib/SimpleScheduler.js
CHANGED
|
@@ -13,7 +13,7 @@ const _formatBytes = require("./formatBytes.js");
|
|
|
13
13
|
const _categorizeTargetRuns = require("./categorizeTargetRuns.js");
|
|
14
14
|
const _targetgraph = require("@lage-run/target-graph");
|
|
15
15
|
const _WrappedTarget = require("./WrappedTarget.js");
|
|
16
|
-
const
|
|
16
|
+
const _runners = require("@lage-run/runners");
|
|
17
17
|
function _check_private_redeclaration(obj, privateCollection) {
|
|
18
18
|
if (privateCollection.has(obj)) {
|
|
19
19
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
@@ -251,7 +251,7 @@ class SimpleScheduler {
|
|
|
251
251
|
},
|
|
252
252
|
workerIdleMemoryLimit: options.workerIdleMemoryLimit
|
|
253
253
|
});
|
|
254
|
-
this.runnerPicker = new
|
|
254
|
+
this.runnerPicker = new _runners.TargetRunnerPicker(options.workerData.runners);
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
257
|
async function generateTargetRunPromise(target) {
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export { NpmScriptRunner } from "./runners/NpmScriptRunner.js";
|
|
2
1
|
export { SimpleScheduler } from "./SimpleScheduler.js";
|
|
3
|
-
export { TargetRunnerPicker } from "./runners/TargetRunnerPicker.js";
|
|
4
|
-
export { WorkerRunner } from "./runners/WorkerRunner.js";
|
|
5
|
-
export { NoOpRunner } from "./runners/NoOpRunner.js";
|
package/lib/index.js
CHANGED
|
@@ -2,31 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
NpmScriptRunner: function() {
|
|
13
|
-
return _NpmScriptRunner.NpmScriptRunner;
|
|
14
|
-
},
|
|
15
|
-
SimpleScheduler: function() {
|
|
5
|
+
Object.defineProperty(exports, "SimpleScheduler", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
16
8
|
return _SimpleScheduler.SimpleScheduler;
|
|
17
|
-
},
|
|
18
|
-
TargetRunnerPicker: function() {
|
|
19
|
-
return _TargetRunnerPicker.TargetRunnerPicker;
|
|
20
|
-
},
|
|
21
|
-
WorkerRunner: function() {
|
|
22
|
-
return _WorkerRunner.WorkerRunner;
|
|
23
|
-
},
|
|
24
|
-
NoOpRunner: function() {
|
|
25
|
-
return _NoOpRunner.NoOpRunner;
|
|
26
9
|
}
|
|
27
10
|
});
|
|
28
|
-
const _NpmScriptRunner = require("./runners/NpmScriptRunner.js");
|
|
29
11
|
const _SimpleScheduler = require("./SimpleScheduler.js");
|
|
30
|
-
const _TargetRunnerPicker = require("./runners/TargetRunnerPicker.js");
|
|
31
|
-
const _WorkerRunner = require("./runners/WorkerRunner.js");
|
|
32
|
-
const _NoOpRunner = require("./runners/NoOpRunner.js");
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
});
|
|
5
5
|
const _createCacheProvider = require("../cache/createCacheProvider.js");
|
|
6
6
|
const _workerthreadspool = require("@lage-run/worker-threads-pool");
|
|
7
|
-
const
|
|
7
|
+
const _runners = require("@lage-run/runners");
|
|
8
8
|
const _worker_threads = require("worker_threads");
|
|
9
9
|
const _logger = /*#__PURE__*/ _interop_require_default(require("@lage-run/logger"));
|
|
10
10
|
function _interop_require_default(obj) {
|
|
@@ -31,7 +31,7 @@ async function setup(options) {
|
|
|
31
31
|
cliArgs: options.taskArgs,
|
|
32
32
|
skipLocalCache: options.skipLocalCache
|
|
33
33
|
});
|
|
34
|
-
const runnerPicker = new
|
|
34
|
+
const runnerPicker = new _runners.TargetRunnerPicker(runners);
|
|
35
35
|
return {
|
|
36
36
|
options,
|
|
37
37
|
runnerPicker,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lage-run/scheduler",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.9",
|
|
4
4
|
"description": "Scheduler for Lage",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
"@lage-run/target-graph": "^0.8.9",
|
|
21
21
|
"@lage-run/logger": "^1.3.0",
|
|
22
22
|
"@lage-run/cache": "^1.3.1",
|
|
23
|
-
"@lage-run/config": "^0.3.
|
|
24
|
-
"@lage-run/hasher": "^1.
|
|
23
|
+
"@lage-run/config": "^0.3.7",
|
|
24
|
+
"@lage-run/hasher": "^1.3.0",
|
|
25
|
+
"@lage-run/runners": "^1.0.1",
|
|
25
26
|
"@lage-run/worker-threads-pool": "^0.8.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@lage-run/scheduler-types": "^0.3.
|
|
29
|
+
"@lage-run/scheduler-types": "^0.3.14",
|
|
29
30
|
"@lage-run/monorepo-scripts": "*"
|
|
30
31
|
},
|
|
31
32
|
"publishConfig": {
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NoOpRunner", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NoOpRunner;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
class NoOpRunner {
|
|
12
|
-
async shouldRun() {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
async run() {
|
|
16
|
-
// pass
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { TargetRunner, TargetRunnerOptions } from "@lage-run/scheduler-types";
|
|
2
|
-
import type { Target } from "@lage-run/target-graph";
|
|
3
|
-
export interface NpmScriptRunnerOptions {
|
|
4
|
-
taskArgs: string[];
|
|
5
|
-
nodeOptions: string;
|
|
6
|
-
npmCmd: string;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Runs a npm script on a target.
|
|
10
|
-
*
|
|
11
|
-
* Requires target to have a packageName, and a task.
|
|
12
|
-
*
|
|
13
|
-
* This class deals with these concepts:
|
|
14
|
-
*
|
|
15
|
-
* 1. Spawning the npm client.
|
|
16
|
-
* 2. Generates npm command line arguments
|
|
17
|
-
* 3. Handling exit & error events from child process.
|
|
18
|
-
* 4. Stream stdout & stderr from child process to a logger.
|
|
19
|
-
* 5. Handling the abort controller signal - kills the child process if started.
|
|
20
|
-
* 6. injecting these environment variables into the child process:
|
|
21
|
-
* - LAGE_PACKAGE_NAME - the name of the package
|
|
22
|
-
* - LAGE_TASK - the name of the task
|
|
23
|
-
* - NODE_OPTIONS - the node options to use when spawning the child process
|
|
24
|
-
* - FORCE_COLOR - set to "1" detect that this is a TTY
|
|
25
|
-
*/
|
|
26
|
-
export declare class NpmScriptRunner implements TargetRunner {
|
|
27
|
-
private options;
|
|
28
|
-
static gracefulKillTimeout: number;
|
|
29
|
-
constructor(options: NpmScriptRunnerOptions);
|
|
30
|
-
private getNpmArgs;
|
|
31
|
-
private hasNpmScript;
|
|
32
|
-
shouldRun(target: Target): Promise<boolean>;
|
|
33
|
-
run(runOptions: TargetRunnerOptions): Promise<void>;
|
|
34
|
-
}
|
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "NpmScriptRunner", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return NpmScriptRunner;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _path = require("path");
|
|
12
|
-
const _promises = require("fs/promises");
|
|
13
|
-
const _child_process = require("child_process");
|
|
14
|
-
function _define_property(obj, key, value) {
|
|
15
|
-
if (key in obj) {
|
|
16
|
-
Object.defineProperty(obj, key, {
|
|
17
|
-
value: value,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
obj[key] = value;
|
|
24
|
-
}
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
class NpmScriptRunner {
|
|
28
|
-
getNpmArgs(task, taskTargs) {
|
|
29
|
-
const extraArgs = taskTargs.length > 0 ? [
|
|
30
|
-
"--",
|
|
31
|
-
...taskTargs
|
|
32
|
-
] : [];
|
|
33
|
-
return [
|
|
34
|
-
"run",
|
|
35
|
-
task,
|
|
36
|
-
...extraArgs
|
|
37
|
-
];
|
|
38
|
-
}
|
|
39
|
-
async hasNpmScript(target) {
|
|
40
|
-
const task = target.options?.script ?? target.task;
|
|
41
|
-
const packageJsonPath = (0, _path.join)(target.cwd, "package.json");
|
|
42
|
-
const packageJson = JSON.parse(await (0, _promises.readFile)(packageJsonPath, "utf8"));
|
|
43
|
-
return !!packageJson.scripts?.[task];
|
|
44
|
-
}
|
|
45
|
-
async shouldRun(target) {
|
|
46
|
-
// By convention, do not run anything if there is no script for this task defined in package.json (counts as "success")
|
|
47
|
-
return await this.hasNpmScript(target);
|
|
48
|
-
}
|
|
49
|
-
async run(runOptions) {
|
|
50
|
-
const { target , weight , abortSignal } = runOptions;
|
|
51
|
-
const { nodeOptions , npmCmd , taskArgs } = this.options;
|
|
52
|
-
const task = target.options?.script ?? target.task;
|
|
53
|
-
let childProcess;
|
|
54
|
-
/**
|
|
55
|
-
* Handling abort signal from the abort controller. Gracefully kills the process,
|
|
56
|
-
* will be handled by exit handler separately to resolve the promise.
|
|
57
|
-
*/ if (abortSignal) {
|
|
58
|
-
if (abortSignal.aborted) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const abortSignalHandler = ()=>{
|
|
62
|
-
abortSignal.removeEventListener("abort", abortSignalHandler);
|
|
63
|
-
if (childProcess && !childProcess.killed) {
|
|
64
|
-
const pid = childProcess.pid;
|
|
65
|
-
process.stdout.write(`Abort signal detected, attempting to killing process id ${pid}\n`);
|
|
66
|
-
childProcess.kill("SIGTERM");
|
|
67
|
-
// wait for "gracefulKillTimeout" to make sure everything is terminated via SIGKILL
|
|
68
|
-
const t = setTimeout(()=>{
|
|
69
|
-
if (childProcess && !childProcess.killed) {
|
|
70
|
-
childProcess.kill("SIGKILL");
|
|
71
|
-
}
|
|
72
|
-
}, NpmScriptRunner.gracefulKillTimeout);
|
|
73
|
-
// Remember that even this timeout needs to be unref'ed, otherwise the process will hang due to this timeout
|
|
74
|
-
if (t.unref) {
|
|
75
|
-
t.unref();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
abortSignal.addEventListener("abort", abortSignalHandler);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Actually spawn the npm client to run the task
|
|
83
|
-
*/ const npmRunArgs = this.getNpmArgs(task, taskArgs);
|
|
84
|
-
const npmRunNodeOptions = [
|
|
85
|
-
nodeOptions,
|
|
86
|
-
target.options?.nodeOptions
|
|
87
|
-
].filter((str)=>str).join(" ");
|
|
88
|
-
await new Promise((resolve, reject)=>{
|
|
89
|
-
childProcess = (0, _child_process.spawn)(npmCmd, npmRunArgs, {
|
|
90
|
-
cwd: target.cwd,
|
|
91
|
-
stdio: [
|
|
92
|
-
"inherit",
|
|
93
|
-
"pipe",
|
|
94
|
-
"pipe"
|
|
95
|
-
],
|
|
96
|
-
// This is required for Windows due to https://nodejs.org/en/blog/vulnerability/april-2024-security-releases-2
|
|
97
|
-
shell: true,
|
|
98
|
-
env: {
|
|
99
|
-
...process.stdout.isTTY && {
|
|
100
|
-
FORCE_COLOR: "1"
|
|
101
|
-
},
|
|
102
|
-
...process.env,
|
|
103
|
-
...npmRunNodeOptions && {
|
|
104
|
-
NODE_OPTIONS: npmRunNodeOptions
|
|
105
|
-
},
|
|
106
|
-
LAGE_PACKAGE_NAME: target.packageName,
|
|
107
|
-
LAGE_TASK: target.task,
|
|
108
|
-
LAGE_WEIGHT: String(weight)
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
let exitHandled = false;
|
|
112
|
-
const handleChildProcessExit = (code)=>{
|
|
113
|
-
childProcess?.off("exit", handleChildProcessExit);
|
|
114
|
-
childProcess?.off("error", handleChildProcessExit);
|
|
115
|
-
if (exitHandled) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
exitHandled = true;
|
|
119
|
-
childProcess?.stdout?.destroy();
|
|
120
|
-
childProcess?.stderr?.destroy();
|
|
121
|
-
childProcess?.stdin?.destroy();
|
|
122
|
-
if (code === 0) {
|
|
123
|
-
return resolve();
|
|
124
|
-
}
|
|
125
|
-
reject(new Error(`NPM Script Runner: ${npmCmd} ${npmRunArgs.join(" ")} exited with code ${code}`));
|
|
126
|
-
};
|
|
127
|
-
const { pid } = childProcess;
|
|
128
|
-
process.stdout.write(`Running ${[
|
|
129
|
-
npmCmd,
|
|
130
|
-
...npmRunArgs
|
|
131
|
-
].join(" ")}, pid: ${pid}\n`);
|
|
132
|
-
const stdout = childProcess.stdout;
|
|
133
|
-
const stderr = childProcess.stderr;
|
|
134
|
-
stdout.pipe(process.stdout);
|
|
135
|
-
stderr.pipe(process.stderr);
|
|
136
|
-
childProcess.on("exit", handleChildProcessExit);
|
|
137
|
-
childProcess.on("error", ()=>handleChildProcessExit(1));
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
constructor(options){
|
|
141
|
-
_define_property(this, "options", void 0);
|
|
142
|
-
this.options = options;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
_define_property(NpmScriptRunner, "gracefulKillTimeout", 2500);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Target } from "@lage-run/target-graph";
|
|
2
|
-
import type { TargetRunner, TargetRunnerPickerOptions } from "@lage-run/scheduler-types";
|
|
3
|
-
export declare class TargetRunnerPicker {
|
|
4
|
-
private options;
|
|
5
|
-
constructor(options: TargetRunnerPickerOptions);
|
|
6
|
-
pick(target: Target): Promise<TargetRunner>;
|
|
7
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "TargetRunnerPicker", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return TargetRunnerPicker;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
12
|
-
const _targetgraph = require("@lage-run/target-graph");
|
|
13
|
-
const _url = require("url");
|
|
14
|
-
function _define_property(obj, key, value) {
|
|
15
|
-
if (key in obj) {
|
|
16
|
-
Object.defineProperty(obj, key, {
|
|
17
|
-
value: value,
|
|
18
|
-
enumerable: true,
|
|
19
|
-
configurable: true,
|
|
20
|
-
writable: true
|
|
21
|
-
});
|
|
22
|
-
} else {
|
|
23
|
-
obj[key] = value;
|
|
24
|
-
}
|
|
25
|
-
return obj;
|
|
26
|
-
}
|
|
27
|
-
function _interop_require_default(obj) {
|
|
28
|
-
return obj && obj.__esModule ? obj : {
|
|
29
|
-
default: obj
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
class TargetRunnerPicker {
|
|
33
|
-
async pick(target) {
|
|
34
|
-
if (target.id === (0, _targetgraph.getStartTargetId)()) {
|
|
35
|
-
return new (await import("./NoOpRunner.js")).NoOpRunner();
|
|
36
|
-
}
|
|
37
|
-
if (!target.type) {
|
|
38
|
-
target.type = "npmScript";
|
|
39
|
-
}
|
|
40
|
-
if (this.options[target.type]) {
|
|
41
|
-
const config = this.options[target.type];
|
|
42
|
-
const { script , options } = config;
|
|
43
|
-
let importScript = script;
|
|
44
|
-
if (!importScript.startsWith("file://")) {
|
|
45
|
-
importScript = (0, _url.pathToFileURL)(importScript).toString();
|
|
46
|
-
}
|
|
47
|
-
const runnerModule = await import(importScript);
|
|
48
|
-
const base = _path.default.basename(script);
|
|
49
|
-
const runnerName = base.replace(_path.default.extname(base), "");
|
|
50
|
-
const runner = typeof runnerModule[runnerName] === "function" ? runnerModule[runnerName] : typeof runnerModule.default === "function" ? runnerModule.default : typeof runnerModule.default[runnerName] === "function" ? runnerModule.default[runnerName] : runnerModule;
|
|
51
|
-
return new runner(options);
|
|
52
|
-
}
|
|
53
|
-
throw new Error(`No runner found for target ${target.id}`);
|
|
54
|
-
}
|
|
55
|
-
constructor(options){
|
|
56
|
-
_define_property(this, "options", void 0);
|
|
57
|
-
this.options = options;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { TargetRunner, TargetRunnerOptions } from "@lage-run/scheduler-types";
|
|
2
|
-
import type { Target } from "@lage-run/target-graph";
|
|
3
|
-
export interface WorkerRunnerOptions {
|
|
4
|
-
taskArgs: string[];
|
|
5
|
-
}
|
|
6
|
-
/**
|
|
7
|
-
* Creates a workerpool per target task definition of "type: worker"
|
|
8
|
-
*
|
|
9
|
-
* Target options are fed into `workerpool`, so target can customize the pool:
|
|
10
|
-
*
|
|
11
|
-
* https://www.npmjs.com/package/workerpool
|
|
12
|
-
*
|
|
13
|
-
* Example:
|
|
14
|
-
*
|
|
15
|
-
* ```ts
|
|
16
|
-
* // lage.config.js
|
|
17
|
-
* {
|
|
18
|
-
* pipeline: {
|
|
19
|
-
* "lint": {
|
|
20
|
-
* type: "worker",
|
|
21
|
-
* options: {
|
|
22
|
-
* worker: "workers/lint.js",
|
|
23
|
-
* maxWorkers: 15
|
|
24
|
-
* }
|
|
25
|
-
* }
|
|
26
|
-
* }
|
|
27
|
-
* }
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* ```js
|
|
31
|
-
* // worker.js
|
|
32
|
-
* module.exports = async function lint({ target, abortSignal }) {
|
|
33
|
-
* if (abortSignal.aborted) {
|
|
34
|
-
* return;
|
|
35
|
-
* }
|
|
36
|
-
*
|
|
37
|
-
* // Do work here - but be sure to have a way to abort via the `abortSignal`
|
|
38
|
-
* }
|
|
39
|
-
* ```
|
|
40
|
-
*/
|
|
41
|
-
export declare class WorkerRunner implements TargetRunner {
|
|
42
|
-
private options;
|
|
43
|
-
static gracefulKillTimeout: number;
|
|
44
|
-
constructor(options: WorkerRunnerOptions);
|
|
45
|
-
shouldRun(target: Target): Promise<boolean>;
|
|
46
|
-
run(runOptions: TargetRunnerOptions): Promise<any>;
|
|
47
|
-
getScriptModule(target: Target): Promise<any>;
|
|
48
|
-
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "WorkerRunner", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: function() {
|
|
8
|
-
return WorkerRunner;
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
const _url = require("url");
|
|
12
|
-
function _define_property(obj, key, value) {
|
|
13
|
-
if (key in obj) {
|
|
14
|
-
Object.defineProperty(obj, key, {
|
|
15
|
-
value: value,
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true
|
|
19
|
-
});
|
|
20
|
-
} else {
|
|
21
|
-
obj[key] = value;
|
|
22
|
-
}
|
|
23
|
-
return obj;
|
|
24
|
-
}
|
|
25
|
-
class WorkerRunner {
|
|
26
|
-
async shouldRun(target) {
|
|
27
|
-
const scriptModule = await this.getScriptModule(target);
|
|
28
|
-
if (typeof scriptModule.shouldRun === "function") {
|
|
29
|
-
return await scriptModule.shouldRun(target);
|
|
30
|
-
}
|
|
31
|
-
return true;
|
|
32
|
-
}
|
|
33
|
-
async run(runOptions) {
|
|
34
|
-
const { target , weight , abortSignal } = runOptions;
|
|
35
|
-
const { taskArgs } = this.options;
|
|
36
|
-
const scriptModule = await this.getScriptModule(target);
|
|
37
|
-
const runFn = typeof scriptModule.run === "function" ? scriptModule.run : typeof scriptModule.default === "function" ? scriptModule.default : scriptModule;
|
|
38
|
-
if (typeof runFn !== "function") {
|
|
39
|
-
throw new Error("WorkerRunner: worker script must export a function; you likely need to use `module.exports = function() {...}`");
|
|
40
|
-
}
|
|
41
|
-
return await runFn({
|
|
42
|
-
target,
|
|
43
|
-
weight,
|
|
44
|
-
taskArgs,
|
|
45
|
-
abortSignal
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
async getScriptModule(target) {
|
|
49
|
-
const scriptFile = target.options?.worker ?? target.options?.script;
|
|
50
|
-
if (!scriptFile) {
|
|
51
|
-
throw new Error('WorkerRunner: "script" configuration is required - e.g. { type: "worker", script: "./worker.js" }');
|
|
52
|
-
}
|
|
53
|
-
let importScript = scriptFile;
|
|
54
|
-
if (!importScript.startsWith("file://")) {
|
|
55
|
-
importScript = (0, _url.pathToFileURL)(importScript).toString();
|
|
56
|
-
}
|
|
57
|
-
return await import(importScript);
|
|
58
|
-
}
|
|
59
|
-
constructor(options){
|
|
60
|
-
_define_property(this, "options", void 0);
|
|
61
|
-
this.options = options;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
_define_property(WorkerRunner, "gracefulKillTimeout", 2500);
|