@ms-cloudpack/api-server 0.6.4 → 0.6.6
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.
|
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
12
|
var _TaskScheduler_scheduler, _TaskScheduler_targetGraphBuilder, _TaskScheduler_reporterTasks;
|
|
13
|
-
import
|
|
13
|
+
import lageLogger from '@lage-run/logger';
|
|
14
14
|
import scheduler from '@lage-run/scheduler';
|
|
15
15
|
import targetGraph, {} from '@lage-run/target-graph';
|
|
16
16
|
import { TargetHasher } from '@lage-run/hasher';
|
|
@@ -26,11 +26,11 @@ export class TaskScheduler {
|
|
|
26
26
|
_TaskScheduler_targetGraphBuilder.set(this, void 0);
|
|
27
27
|
_TaskScheduler_reporterTasks.set(this, new Map());
|
|
28
28
|
const { reporter, root } = options;
|
|
29
|
-
const logger = new Logger();
|
|
29
|
+
const logger = new lageLogger.Logger();
|
|
30
30
|
const reporterTasks = __classPrivateFieldGet(this, _TaskScheduler_reporterTasks, "f");
|
|
31
31
|
logger.addReporter({
|
|
32
32
|
log(entry) {
|
|
33
|
-
if (entry.msg && entry.level <= LogLevel.warn && entry.data?.target) {
|
|
33
|
+
if (entry.msg && entry.level <= lageLogger.LogLevel.warn && entry.data?.target) {
|
|
34
34
|
const target = entry.data?.target;
|
|
35
35
|
if (reporterTasks.has(target.id)) {
|
|
36
36
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -68,11 +68,11 @@ export class TaskScheduler {
|
|
|
68
68
|
}
|
|
69
69
|
if (entry.msg) {
|
|
70
70
|
const logLevelToConsoleFnMap = {
|
|
71
|
-
[LogLevel.error]: console.error,
|
|
72
|
-
[LogLevel.warn]: console.warn,
|
|
73
|
-
[LogLevel.info]: console.info,
|
|
74
|
-
[LogLevel.verbose]: console.debug,
|
|
75
|
-
[LogLevel.silly]: console.debug,
|
|
71
|
+
[lageLogger.LogLevel.error]: console.error,
|
|
72
|
+
[lageLogger.LogLevel.warn]: console.warn,
|
|
73
|
+
[lageLogger.LogLevel.info]: console.info,
|
|
74
|
+
[lageLogger.LogLevel.verbose]: console.debug,
|
|
75
|
+
[lageLogger.LogLevel.silly]: console.debug,
|
|
76
76
|
};
|
|
77
77
|
logLevelToConsoleFnMap[entry.level](entry.msg);
|
|
78
78
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TaskScheduler.js","sourceRoot":"","sources":["../../src/utilities/TaskScheduler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TaskScheduler.js","sourceRoot":"","sources":["../../src/utilities/TaskScheduler.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,UAAU,MAAM,kBAAkB,CAAC;AAC1C,OAAO,SAAS,MAAM,qBAAqB,CAAC;AAC5C,OAAO,WAAW,EAAE,EAAe,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,MAAM,IAAI,CAAC;AAIpB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAO/C;;GAEG;AACH,MAAM,OAAO,aAAa;IAMxB,YAAY,OAA6B;QALzC,2CAAsC;QACtC,oDAAoD;QAEpD,uCAAiB,IAAI,GAAG,EAA4B,EAAC;QAGnD,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;QACnC,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;QAEvC,MAAM,aAAa,GAAG,uBAAA,IAAI,oCAAe,CAAC;QAE1C,MA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AAO,CAAC,EAAE;YACV,IAAI,CAAC,YAAY,KAAK,EAAE;gBACtB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;gBACzB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;aACxB;iBAAM;gBACL,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1B;SACF;IACH,CAAC;CACF","sourcesContent":["import lageLogger from '@lage-run/logger';\nimport scheduler from '@lage-run/scheduler';\nimport targetGraph, { type Target } from '@lage-run/target-graph';\nimport { TargetHasher } from '@lage-run/hasher';\nimport os from 'os';\nimport type { BundleRequest } from '../types/BundleRequest.js';\nimport type { TaskReporter, TaskReporterTask } from '@ms-cloudpack/task-reporter';\n\nimport { createRequire } from 'node:module';\nconst require = createRequire(import.meta.url);\n\ninterface TaskSchedulerOptions {\n reporter: TaskReporter;\n root: string;\n}\n\n/**\n * A class to abstract the creation of the lage scheduler and scheduling tasks\n */\nexport class TaskScheduler {\n #scheduler: scheduler.SimpleScheduler;\n #targetGraphBuilder: targetGraph.TargetGraphBuilder;\n\n #reporterTasks = new Map<string, TaskReporterTask>();\n\n constructor(options: TaskSchedulerOptions) {\n const { reporter, root } = options;\n const logger = new lageLogger.Logger();\n\n const reporterTasks = this.#reporterTasks;\n\n logger.addReporter({\n log(entry) {\n if (entry.msg && entry.level <= lageLogger.LogLevel.warn && entry.data?.target) {\n const target = entry.data?.target as Target;\n if (reporterTasks.has(target.id)) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n reporterTasks.get(target.id)!.message += entry.msg;\n }\n return;\n }\n\n if (entry.data && entry.data.status) {\n const { status } = entry.data;\n const target = entry.data.target as Target;\n\n // Ensure task is in the reporterTasks map\n const task = reporterTasks.has(target.id)\n ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n reporterTasks.get(target.id)!\n : reporter.addTask(target.label, true);\n\n reporterTasks.set(target.id, task);\n\n switch (status) {\n case 'running':\n task.start();\n break;\n\n case 'success':\n task.complete({ status: 'complete' });\n break;\n\n case 'skipped':\n task.complete({ status: 'skip' });\n break;\n\n case 'failed':\n task.complete({ status: 'fail' });\n break;\n\n case 'aborted':\n task.complete({ status: 'abort' });\n break;\n }\n return;\n }\n\n if (entry.msg) {\n const logLevelToConsoleFnMap = {\n [lageLogger.LogLevel.error]: console.error,\n [lageLogger.LogLevel.warn]: console.warn,\n [lageLogger.LogLevel.info]: console.info,\n [lageLogger.LogLevel.verbose]: console.debug,\n [lageLogger.LogLevel.silly]: console.debug,\n };\n\n logLevelToConsoleFnMap[entry.level](entry.msg);\n return;\n }\n },\n\n summarize() {\n // noop\n },\n });\n\n const runners = {\n worker: {\n script: require.resolve('@lage-run/scheduler/lib/runners/WorkerRunner.js'),\n options: {},\n },\n noop: {\n script: require.resolve('@lage-run/scheduler/lib/runners/NoOpRunner.js'),\n options: {},\n },\n };\n\n const hasher = new TargetHasher({ root, environmentGlob: [] });\n\n this.#targetGraphBuilder = new targetGraph.TargetGraphBuilder();\n this.#scheduler = new scheduler.SimpleScheduler({\n concurrency: 10,\n continueOnError: true,\n logger,\n maxWorkersPerTask: new Map(),\n workerData: {\n runners,\n root,\n taskArgs: [],\n },\n shouldCache: true,\n shouldResetCache: false,\n workerIdleMemoryLimit: os.totalmem(),\n hasher,\n });\n }\n\n // Schedules task to be run according to the bundle request that came through from the bundler server\n // TODO: from a bundle request, we should be able to determine if we need to auto add several targets into the graph\n async scheduleTask<T extends BundleRequest>(\n bundleRequest: T,\n scripts: Record<string, string>,\n options: {\n rerun?: boolean;\n },\n ) {\n const cwd = bundleRequest.packagePath;\n const target: Target = {\n id: bundleRequest.id,\n label: `${bundleRequest.packageName} bundle`,\n task: 'bundle',\n type: 'worker',\n cwd: bundleRequest.packagePath,\n dependencies: [],\n dependents: [],\n depSpecs: [],\n options: {\n script: scripts.bundle ?? '',\n bundleRequest,\n },\n };\n\n this.#targetGraphBuilder.addTarget(target);\n\n const graph = this.#targetGraphBuilder.build();\n\n try {\n await this.#scheduler.run(cwd, graph, options.rerun);\n } catch (e) {\n if (e instanceof Error) {\n console.error(e.message);\n console.error(e.stack);\n } else {\n console.error(String(e));\n }\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/api-server",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.6",
|
|
4
4
|
"description": "An implementation of the API server that does interacts with a task scheduler.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"@lage-run/target-graph": "^0.8.6",
|
|
19
19
|
"@lage-run/hasher": "^1.0.0",
|
|
20
20
|
"@ms-cloudpack/bundler-types": "^0.13.0",
|
|
21
|
-
"@ms-cloudpack/config": "^0.
|
|
21
|
+
"@ms-cloudpack/config": "^0.7.0",
|
|
22
22
|
"@ms-cloudpack/create-express-app": "^1.3.5",
|
|
23
23
|
"@ms-cloudpack/data-bus": "^0.2.1",
|
|
24
24
|
"@ms-cloudpack/package-utilities": "^3.1.1",
|
|
25
25
|
"@ms-cloudpack/path-string-parsing": "^1.0.1",
|
|
26
|
-
"@ms-cloudpack/task-reporter": "^0.
|
|
26
|
+
"@ms-cloudpack/task-reporter": "^0.4.0",
|
|
27
27
|
"@ms-cloudpack/telemetry": "^0.3.2",
|
|
28
28
|
"@trpc/client": "^10.21.1",
|
|
29
29
|
"@trpc/server": "^10.21.1",
|