@tskmgr/client 0.0.9 → 0.1.0
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/package.json +8 -4
- package/src/index.d.ts +3 -0
- package/src/index.js +5 -2
- package/src/index.js.map +1 -1
- package/src/lib/client-example.d.ts +2 -0
- package/src/lib/client-example.js +53 -27
- package/src/lib/client-example.js.map +1 -1
- package/src/lib/client-factory.d.ts +2 -1
- package/src/lib/client-factory.js.map +1 -1
- package/src/lib/client-options.d.ts +12 -0
- package/src/lib/client-options.js +3 -0
- package/src/lib/client-options.js.map +1 -0
- package/src/lib/client.d.ts +16 -24
- package/src/lib/client.js +89 -82
- package/src/lib/client.js.map +1 -1
- package/src/lib/run-tasks-result.d.ts +9 -0
- package/src/lib/run-tasks-result.js +14 -0
- package/src/lib/run-tasks-result.js.map +1 -0
- package/src/lib/task-result.d.ts +10 -0
- package/src/lib/task-result.js +3 -0
- package/src/lib/task-result.js.map +1 -0
- package/src/lib/utils.d.ts +17 -0
- package/src/lib/utils.js +68 -0
- package/src/lib/utils.js.map +1 -0
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tskmgr/client",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"node-fetch": "^2.6.7",
|
|
7
|
-
"
|
|
7
|
+
"systeminformation": "^5.16.6"
|
|
8
8
|
},
|
|
9
9
|
"main": "./src/index.js",
|
|
10
|
-
"
|
|
11
|
-
"peerDependencies": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"peerDependencies": {
|
|
12
|
+
"@tskmgr/common": "0.0.1",
|
|
13
|
+
"uuid": "^9.0.0",
|
|
14
|
+
"tslib": "^2.0.0"
|
|
15
|
+
}
|
|
12
16
|
}
|
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
tslib_1.__exportStar(require("./lib/client"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./lib/client-options"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./lib/client-factory"), exports);
|
|
7
|
+
tslib_1.__exportStar(require("./lib/run-tasks-result"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./lib/task-result"), exports);
|
|
6
9
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/client/src/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../libs/client/src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,+DAAqC;AACrC,+DAAqC;AAErC,iEAAuC;AACvC,4DAAkC"}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* IntelliJ debug:
|
|
3
3
|
* Node parameters: --require ts-node/register --require tsconfig-paths/register
|
|
4
4
|
* Environment variables: TS_NODE_PROJECT=libs/client/tsconfig.lib.json
|
|
5
|
+
*
|
|
5
6
|
* Start API: nx serve api
|
|
7
|
+
* Command: nx reset && TS_NODE_PROJECT=libs/client/tsconfig.lib.json node --require ts-node/register --require tsconfig-paths/register libs/client/src/lib/client-example.ts
|
|
6
8
|
*/
|
|
7
9
|
export {};
|
|
@@ -3,7 +3,9 @@
|
|
|
3
3
|
* IntelliJ debug:
|
|
4
4
|
* Node parameters: --require ts-node/register --require tsconfig-paths/register
|
|
5
5
|
* Environment variables: TS_NODE_PROJECT=libs/client/tsconfig.lib.json
|
|
6
|
+
*
|
|
6
7
|
* Start API: nx serve api
|
|
8
|
+
* Command: nx reset && TS_NODE_PROJECT=libs/client/tsconfig.lib.json node --require ts-node/register --require tsconfig-paths/register libs/client/src/lib/client-example.ts
|
|
7
9
|
*/
|
|
8
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
11
|
const tslib_1 = require("tslib");
|
|
@@ -12,38 +14,54 @@ const common_1 = require("@tskmgr/common");
|
|
|
12
14
|
const client_factory_1 = require("./client-factory");
|
|
13
15
|
const uuid_1 = require("uuid");
|
|
14
16
|
delete process.env.TS_NODE_PROJECT;
|
|
15
|
-
const
|
|
17
|
+
const debug = false;
|
|
18
|
+
const options = { parallel: 1, dataCallback, errorCallback };
|
|
16
19
|
const client = client_factory_1.ClientFactory.createNew('http://localhost:3333', 'RUNNER_1', options);
|
|
17
|
-
|
|
20
|
+
let exitCode = 0;
|
|
21
|
+
let run;
|
|
22
|
+
(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
18
23
|
try {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
name: nxTask.target.project,
|
|
22
|
-
type: nxTask.target.target,
|
|
23
|
-
command: nxTask.command,
|
|
24
|
-
options: { shell: true },
|
|
25
|
-
priority: common_1.TaskPriority.Longest,
|
|
26
|
-
};
|
|
27
|
-
});
|
|
28
|
-
const newRun = yield client.createRun({
|
|
24
|
+
// 1. Create the new run
|
|
25
|
+
run = yield client.createRun({
|
|
29
26
|
name: (0, uuid_1.v4)(),
|
|
30
27
|
type: '123',
|
|
31
|
-
pullRequestName: '123',
|
|
32
28
|
prioritization: [common_1.TaskPriority.Longest],
|
|
33
29
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
log(run);
|
|
31
|
+
// 2. Leader should create some tasks to run
|
|
32
|
+
const res = yield client.setLeader(run.id);
|
|
33
|
+
if (res.leader) {
|
|
34
|
+
const tasks = getNxTasks().map((nxTask) => {
|
|
35
|
+
return {
|
|
36
|
+
name: nxTask.target.project,
|
|
37
|
+
type: nxTask.target.target,
|
|
38
|
+
command: nxTask.command,
|
|
39
|
+
options: { shell: true },
|
|
40
|
+
priority: common_1.TaskPriority.Longest,
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
const createdTasks = yield client.createTasks(run.id, { tasks });
|
|
44
|
+
log(createdTasks);
|
|
45
|
+
const closeRun = yield client.closeRun(run.id);
|
|
46
|
+
log(closeRun);
|
|
47
|
+
}
|
|
48
|
+
// 3. Execute tasks
|
|
49
|
+
const result = yield client.runTasks(run.id);
|
|
50
|
+
if (result.failed) {
|
|
51
|
+
// if failFast set to false, runTasks will complete without throwing errors.
|
|
52
|
+
exitCode = 1;
|
|
41
53
|
}
|
|
42
|
-
yield client.runTasks(newRun._id);
|
|
43
54
|
}
|
|
44
55
|
catch (e) {
|
|
45
|
-
|
|
46
|
-
|
|
56
|
+
log(e);
|
|
57
|
+
exitCode = 1;
|
|
58
|
+
}
|
|
59
|
+
finally {
|
|
60
|
+
// 4. See results
|
|
61
|
+
console.log('--------------------------------------------------');
|
|
62
|
+
console.log(` tskmgr run: http://localhost:4200/runs/${run.id}`);
|
|
63
|
+
console.log('--------------------------------------------------');
|
|
64
|
+
process.exit(exitCode);
|
|
47
65
|
}
|
|
48
66
|
}))();
|
|
49
67
|
function getNxTasks() {
|
|
@@ -56,13 +74,21 @@ function getNxTasks() {
|
|
|
56
74
|
return tasks;
|
|
57
75
|
}
|
|
58
76
|
function dataCallback(task, data, cached) {
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
if (data.startsWith(`> nx run ${task.name}:${task.type}`) &&
|
|
77
|
+
// > nx run frontend:lint [existing outputs match the cache, left as is]
|
|
78
|
+
// > nx run client:lint [local cache]
|
|
79
|
+
if ((data.startsWith(`> nx run ${task.name}:${task.type}`) &&
|
|
80
|
+
data.endsWith('[existing outputs match the cache, left as is]')) ||
|
|
81
|
+
data.endsWith('[local cache]')) {
|
|
62
82
|
cached();
|
|
63
83
|
}
|
|
84
|
+
console.log(`[stdout] ${data}`);
|
|
64
85
|
}
|
|
65
86
|
function errorCallback(task, data) {
|
|
66
|
-
console.log(data);
|
|
87
|
+
console.log(`[stderr] ${data}`);
|
|
88
|
+
}
|
|
89
|
+
function log(message) {
|
|
90
|
+
if (debug) {
|
|
91
|
+
console.log(message);
|
|
92
|
+
}
|
|
67
93
|
}
|
|
68
94
|
//# sourceMappingURL=client-example.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-example.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-example.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"client-example.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-example.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAEH,iDAAyC;AACzC,2CAAwE;AAExE,qDAAiD;AACjD,+BAAkC;AAElC,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC;AAEnC,MAAM,KAAK,GAAG,KAAK,CAAC;AACpB,MAAM,OAAO,GAAkB,EAAE,QAAQ,EAAE,CAAC,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC;AAC5E,MAAM,MAAM,GAAG,8BAAa,CAAC,SAAS,CAAC,uBAAuB,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAErF,IAAI,QAAQ,GAAG,CAAC,CAAC;AACjB,IAAI,GAAQ,CAAC;AAEb,CAAC,GAAS,EAAE;IACV,IAAI;QACF,wBAAwB;QACxB,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC;YAC3B,IAAI,EAAE,IAAA,SAAI,GAAE;YACZ,IAAI,EAAE,KAAK;YACX,cAAc,EAAE,CAAC,qBAAY,CAAC,OAAO,CAAC;SACvC,CAAC,CAAC;QACH,GAAG,CAAC,GAAG,CAAC,CAAC;QAET,4CAA4C;QAC5C,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAC3C,IA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EL,SAAS,UAAU;IACjB,MAAM,KAAK,GAAa;QACtB,oEAAoE;QACpE,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAQ,EAAC,2CAA2C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;QACrF,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAQ,EAAC,2CAA2C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;QACrF,GAAG,IAAI,CAAC,KAAK,CAAC,IAAA,wBAAQ,EAAC,4CAA4C,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,KAAK;KACvF,CAAC;IACF,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,IAAU,EAAE,IAAY,EAAE,MAAkB;IAChE,yEAAyE;IACzE,sCAAsC;IACtC,IACE,CAAC,IAAI,CAAC,UAAU,CAAC,YAAY,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,gDAAgD,CAAC,CAAC;QAClE,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAC9B;QACA,MAAM,EAAE,CAAC;KACV;IAED,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,aAAa,CAAC,IAAU,EAAE,IAAY;IAC7C,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,GAAG,CAAC,OAAY;IACvB,IAAI,KAAK,EAAE;QACT,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;KACtB;AACH,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Client
|
|
1
|
+
import { Client } from './client';
|
|
2
|
+
import { ClientOptions } from './client-options';
|
|
2
3
|
export declare class ClientFactory {
|
|
3
4
|
static createNew(baseUrl: string, //
|
|
4
5
|
runnerId: string, options?: ClientOptions): Client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-factory.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-factory.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"client-factory.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-factory.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAElC,2CAAwC;AAExC,MAAa,aAAa;IACjB,MAAM,CAAC,SAAS,CACrB,OAAe,EAAE,EAAE;IACnB,QAAgB,EAChB,OAAuB;QAEvB,OAAO,IAAI,eAAM,CACf,eAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE;QAC1B,QAAQ,kCACH,eAAM,CAAC,cAAc,GAAK,OAAO,EACvC,CAAC;IACJ,CAAC;CACF;AAZD,sCAYC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Task } from '@tskmgr/common';
|
|
3
|
+
import { SpawnOptionsWithoutStdio } from 'child_process';
|
|
4
|
+
export interface ClientOptions {
|
|
5
|
+
parallel?: number;
|
|
6
|
+
dataCallback?: (task: Task, data: string, cached: () => void) => void;
|
|
7
|
+
errorCallback?: (task: Task, data: string) => void;
|
|
8
|
+
pollingDelayMs?: number;
|
|
9
|
+
retryDelayMs?: number;
|
|
10
|
+
retryCount?: number;
|
|
11
|
+
spawnOptions?: SpawnOptionsWithoutStdio;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-options.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client-options.ts"],"names":[],"mappings":""}
|
package/src/lib/client.d.ts
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export interface ClientOptions {
|
|
5
|
-
parallel?: number;
|
|
6
|
-
dataCallback?: (task: Task, data: string, cached: () => void) => void;
|
|
7
|
-
errorCallback?: (task: Task, data: string) => void;
|
|
8
|
-
pollingDelayMs?: number;
|
|
9
|
-
retryDelayMs?: number;
|
|
10
|
-
retryCount?: number;
|
|
11
|
-
spawnOptions?: SpawnOptionsWithoutStdio;
|
|
12
|
-
}
|
|
1
|
+
import { ApiUrl, Run, CompleteTaskDto, CreateRunRequestDto, CreateTasksDto, StartTaskDto, StartTaskResponseDto, Task, File as File_, SetLeaderResponseDto, CreateFileRequestDto } from '@tskmgr/common';
|
|
2
|
+
import { RunTasksResult } from './run-tasks-result';
|
|
3
|
+
import { ClientOptions } from './client-options';
|
|
13
4
|
export declare class Client {
|
|
14
5
|
private readonly apiUrl;
|
|
15
6
|
private readonly runnerId;
|
|
16
7
|
private readonly options;
|
|
17
8
|
static readonly DefaultOptions: ClientOptions;
|
|
18
|
-
constructor(apiUrl: ApiUrl,
|
|
19
|
-
runnerId: string, options: ClientOptions);
|
|
9
|
+
constructor(apiUrl: ApiUrl, runnerId: string, options: ClientOptions);
|
|
20
10
|
createRun(params: CreateRunRequestDto): Promise<Run>;
|
|
21
|
-
closeRun(runId:
|
|
22
|
-
abortRun(runId:
|
|
23
|
-
failRun(runId:
|
|
24
|
-
setLeader(runId:
|
|
25
|
-
createTasks(runId:
|
|
26
|
-
startTask(runId:
|
|
27
|
-
runTasks(runId:
|
|
28
|
-
completeTask(taskId:
|
|
29
|
-
failTask(taskId:
|
|
11
|
+
closeRun(runId: number): Promise<Run>;
|
|
12
|
+
abortRun(runId: number): Promise<Run>;
|
|
13
|
+
failRun(runId: number): Promise<Run>;
|
|
14
|
+
setLeader(runId: number): Promise<SetLeaderResponseDto>;
|
|
15
|
+
createTasks(runId: number, params: CreateTasksDto): Promise<Task[]>;
|
|
16
|
+
startTask(runId: number, params: StartTaskDto): Promise<StartTaskResponseDto>;
|
|
17
|
+
runTasks(runId: number): Promise<RunTasksResult>;
|
|
18
|
+
completeTask(taskId: number, params: CompleteTaskDto): Promise<Task>;
|
|
19
|
+
failTask(taskId: number): Promise<Task>;
|
|
20
|
+
uploadRunFile(runId: number, path: string, params: CreateFileRequestDto): Promise<File_>;
|
|
21
|
+
uploadTaskFile(taskId: number, path: string, params: CreateFileRequestDto): Promise<File_>;
|
|
22
|
+
private uploadFile;
|
|
30
23
|
private defaultTaskRunner;
|
|
31
24
|
}
|
|
32
|
-
export declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio, dataCallback?: (data: string) => void, errorCallback?: (data: string) => void): Promise<ChildProcess>;
|
package/src/lib/client.js
CHANGED
|
@@ -1,130 +1,167 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.Client = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const child_process_1 = require("child_process");
|
|
6
5
|
const node_fetch_1 = require("node-fetch");
|
|
7
|
-
const
|
|
6
|
+
const FormData = require("form-data");
|
|
7
|
+
const utils_1 = require("./utils");
|
|
8
|
+
const run_tasks_result_1 = require("./run-tasks-result");
|
|
9
|
+
const fs_1 = require("fs");
|
|
8
10
|
class Client {
|
|
9
|
-
constructor(apiUrl,
|
|
10
|
-
runnerId, options) {
|
|
11
|
+
constructor(apiUrl, runnerId, options) {
|
|
11
12
|
this.apiUrl = apiUrl;
|
|
12
13
|
this.runnerId = runnerId;
|
|
13
14
|
this.options = options;
|
|
14
15
|
}
|
|
15
16
|
createRun(params) {
|
|
16
|
-
return
|
|
17
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
17
18
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.createRunUrl(), {
|
|
18
19
|
headers: { 'Content-Type': 'application/json' },
|
|
19
20
|
method: 'POST',
|
|
20
21
|
body: JSON.stringify(params),
|
|
21
22
|
});
|
|
22
|
-
return yield checkStatus(res).json();
|
|
23
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
closeRun(runId) {
|
|
26
|
-
return
|
|
27
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
27
28
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.closeRunUrl(runId), {
|
|
28
29
|
headers: { 'Content-Type': 'application/json' },
|
|
29
30
|
method: 'PUT',
|
|
30
31
|
});
|
|
31
|
-
return yield checkStatus(res).json();
|
|
32
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
32
33
|
});
|
|
33
34
|
}
|
|
34
35
|
abortRun(runId) {
|
|
35
|
-
return
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
36
37
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.abortRunUrl(runId), {
|
|
37
38
|
headers: { 'Content-Type': 'application/json' },
|
|
38
39
|
method: 'PUT',
|
|
39
40
|
});
|
|
40
|
-
return yield checkStatus(res).json();
|
|
41
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
failRun(runId) {
|
|
44
|
-
return
|
|
45
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
45
46
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.failRunUrl(runId), {
|
|
46
47
|
headers: { 'Content-Type': 'application/json' },
|
|
47
48
|
method: 'PUT',
|
|
48
49
|
});
|
|
49
|
-
return yield checkStatus(res).json();
|
|
50
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
50
51
|
});
|
|
51
52
|
}
|
|
52
53
|
setLeader(runId) {
|
|
53
|
-
return
|
|
54
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
54
55
|
const params = { runnerId: this.runnerId };
|
|
55
56
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.setLeaderUrl(runId), {
|
|
56
57
|
headers: { 'Content-Type': 'application/json' },
|
|
57
58
|
method: 'PUT',
|
|
58
59
|
body: JSON.stringify(params),
|
|
59
60
|
});
|
|
60
|
-
return yield checkStatus(res).json();
|
|
61
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
64
|
createTasks(runId, params) {
|
|
64
|
-
return
|
|
65
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
65
66
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.createTasksUrl(runId), {
|
|
66
67
|
headers: { 'Content-Type': 'application/json' },
|
|
67
68
|
method: 'POST',
|
|
68
69
|
body: JSON.stringify(params),
|
|
69
70
|
});
|
|
70
|
-
return yield checkStatus(res).json();
|
|
71
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
71
72
|
});
|
|
72
73
|
}
|
|
73
74
|
startTask(runId, params) {
|
|
74
|
-
return
|
|
75
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
75
76
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.startTaskUrl(runId), {
|
|
76
77
|
headers: { 'Content-Type': 'application/json' },
|
|
77
78
|
method: 'PUT',
|
|
78
79
|
body: JSON.stringify(params),
|
|
79
80
|
});
|
|
80
|
-
return yield checkStatus(res).json();
|
|
81
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
81
82
|
});
|
|
82
83
|
}
|
|
83
84
|
runTasks(runId) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
85
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const taskRunners = [];
|
|
87
|
+
for (let i = 0; i < this.options.parallel; i++) {
|
|
88
|
+
taskRunners.push(this.defaultTaskRunner(runId));
|
|
89
|
+
}
|
|
90
|
+
const taskResults = yield Promise.all(taskRunners);
|
|
91
|
+
return new run_tasks_result_1.RunTasksResult(taskResults.flatMap((x) => x));
|
|
92
|
+
});
|
|
89
93
|
}
|
|
90
94
|
completeTask(taskId, params) {
|
|
91
|
-
return
|
|
95
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
92
96
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.completeTaskUrl(taskId), {
|
|
93
97
|
headers: { 'Content-Type': 'application/json' },
|
|
94
98
|
method: 'PUT',
|
|
95
99
|
body: JSON.stringify(params),
|
|
96
100
|
});
|
|
97
|
-
return yield checkStatus(res).json();
|
|
101
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
98
102
|
});
|
|
99
103
|
}
|
|
100
104
|
failTask(taskId) {
|
|
101
|
-
return
|
|
105
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
102
106
|
const res = yield (0, node_fetch_1.default)(this.apiUrl.failTaskUrl(taskId), {
|
|
103
107
|
headers: { 'Content-Type': 'application/json' },
|
|
104
108
|
method: 'PUT',
|
|
105
109
|
});
|
|
106
|
-
return yield checkStatus(res).json();
|
|
110
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
uploadRunFile(runId, path, params) {
|
|
114
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
115
|
+
return this.uploadFile(this.apiUrl.createFileRunUrl(runId), path, params);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
uploadTaskFile(taskId, path, params) {
|
|
119
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
return this.uploadFile(this.apiUrl.createFileTaskUrl(taskId), path, params);
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
uploadFile(url, path, params) {
|
|
124
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
// https://github.com/node-fetch/node-fetch/tree/2.x#post-with-form-data-detect-multipart
|
|
126
|
+
// https://github.com/form-data/form-data#readme
|
|
127
|
+
const formData = new FormData();
|
|
128
|
+
formData.append('file', (0, fs_1.createReadStream)(path));
|
|
129
|
+
if (params.type) {
|
|
130
|
+
formData.append('type', params.type);
|
|
131
|
+
}
|
|
132
|
+
if (params.description) {
|
|
133
|
+
formData.append('description', params.description);
|
|
134
|
+
}
|
|
135
|
+
const res = yield (0, node_fetch_1.default)(url, {
|
|
136
|
+
method: 'POST',
|
|
137
|
+
body: formData,
|
|
138
|
+
});
|
|
139
|
+
return yield (0, utils_1.checkStatus)(res).json();
|
|
107
140
|
});
|
|
108
141
|
}
|
|
109
142
|
defaultTaskRunner(runId) {
|
|
110
|
-
return
|
|
143
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
144
|
+
const taskResults = [];
|
|
111
145
|
let _continue = true;
|
|
112
146
|
while (_continue) {
|
|
113
147
|
const response = yield this.startTask(runId, { runnerId: this.runnerId });
|
|
114
148
|
if (!response.continue) {
|
|
115
149
|
_continue = false;
|
|
116
|
-
}
|
|
117
|
-
if (!response.continue && !response.task) {
|
|
118
150
|
continue;
|
|
119
151
|
}
|
|
120
152
|
if (!response.task) {
|
|
153
|
+
// TODO: this should output only once per runner
|
|
121
154
|
console.log(`polling for a new task in: ${this.options.pollingDelayMs} ms`);
|
|
122
|
-
yield delay(this.options.pollingDelayMs);
|
|
155
|
+
yield (0, utils_1.delay)(this.options.pollingDelayMs);
|
|
123
156
|
continue;
|
|
124
157
|
}
|
|
125
158
|
const { run, task } = response;
|
|
126
159
|
let cached = false;
|
|
127
160
|
let hasCompleted = true;
|
|
161
|
+
let childProcess;
|
|
162
|
+
let error;
|
|
163
|
+
const taskLogFilename = (0, utils_1.getTaskLogFilename)(task.id);
|
|
164
|
+
const writeStream = (0, fs_1.createWriteStream)(taskLogFilename);
|
|
128
165
|
const dataHandler = (data) => {
|
|
129
166
|
this.options.dataCallback(task, data, () => (cached = true));
|
|
130
167
|
};
|
|
@@ -132,23 +169,37 @@ class Client {
|
|
|
132
169
|
this.options.errorCallback(task, data);
|
|
133
170
|
};
|
|
134
171
|
try {
|
|
135
|
-
yield spawnAsync(task.command, task.arguments, Object.assign(Object.assign({}, task.options), this.options.spawnOptions),
|
|
172
|
+
childProcess = yield (0, utils_1.spawnAsync)(task.command, task.arguments, Object.assign(Object.assign({}, task.options), this.options.spawnOptions), {
|
|
173
|
+
writeStream,
|
|
174
|
+
dataCallback: dataHandler,
|
|
175
|
+
errorCallback: errorHandler,
|
|
176
|
+
});
|
|
136
177
|
}
|
|
137
|
-
catch (
|
|
178
|
+
catch (err) {
|
|
179
|
+
error = err;
|
|
138
180
|
hasCompleted = false;
|
|
139
181
|
if (run.failFast) {
|
|
140
|
-
|
|
182
|
+
// TODO: should abort all running tasks by current client
|
|
183
|
+
throw err;
|
|
141
184
|
}
|
|
142
185
|
}
|
|
143
186
|
finally {
|
|
187
|
+
taskResults.push({ run, task, childProcess, hasCompleted, error });
|
|
144
188
|
if (hasCompleted) {
|
|
145
|
-
yield this.completeTask(task.
|
|
189
|
+
yield this.completeTask(task.id, { cached });
|
|
146
190
|
}
|
|
147
191
|
else {
|
|
148
|
-
yield this.failTask(task.
|
|
192
|
+
yield this.failTask(task.id);
|
|
149
193
|
}
|
|
194
|
+
writeStream.close();
|
|
195
|
+
yield this.uploadTaskFile(task.id, taskLogFilename, {
|
|
196
|
+
type: 'log',
|
|
197
|
+
description: `Log for task ${task.id}`,
|
|
198
|
+
});
|
|
199
|
+
(0, fs_1.unlinkSync)(taskLogFilename);
|
|
150
200
|
}
|
|
151
201
|
}
|
|
202
|
+
return taskResults;
|
|
152
203
|
});
|
|
153
204
|
}
|
|
154
205
|
}
|
|
@@ -159,52 +210,8 @@ Client.DefaultOptions = {
|
|
|
159
210
|
dataCallback: (task, data, cached) => { },
|
|
160
211
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
161
212
|
errorCallback: (task, data) => { },
|
|
162
|
-
pollingDelayMs:
|
|
213
|
+
pollingDelayMs: 1000,
|
|
163
214
|
retryDelayMs: 5000,
|
|
164
215
|
retryCount: 2,
|
|
165
216
|
};
|
|
166
|
-
function delay(ms) {
|
|
167
|
-
return new Promise((resolve) => {
|
|
168
|
-
setTimeout(resolve, ms);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
function spawnAsync(command, args, options, dataCallback, errorCallback) {
|
|
172
|
-
return (0, tslib_1.__awaiter)(this, void 0, void 0, function* () {
|
|
173
|
-
return new Promise((resolve, reject) => {
|
|
174
|
-
const childProcess = (0, child_process_1.spawn)(command, args, options);
|
|
175
|
-
const readlineStdout = (0, readline_1.createInterface)({ input: childProcess.stdout });
|
|
176
|
-
const readlineStderr = (0, readline_1.createInterface)({ input: childProcess.stderr });
|
|
177
|
-
readlineStdout.on('line', dataCallback);
|
|
178
|
-
readlineStderr.on('line', errorCallback);
|
|
179
|
-
childProcess.on('close', (code) => {
|
|
180
|
-
if (code === 0) {
|
|
181
|
-
resolve(childProcess);
|
|
182
|
-
}
|
|
183
|
-
else {
|
|
184
|
-
reject(childProcess);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
childProcess.on('error', (err) => {
|
|
188
|
-
reject(childProcess); // TODO: try to return error message
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
exports.spawnAsync = spawnAsync;
|
|
194
|
-
class HTTPResponseError extends Error {
|
|
195
|
-
constructor(response) {
|
|
196
|
-
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
197
|
-
this.response = response;
|
|
198
|
-
this.response = response;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
const checkStatus = (response) => {
|
|
202
|
-
if (response.ok) {
|
|
203
|
-
// response.status >= 200 && response.status < 300
|
|
204
|
-
return response;
|
|
205
|
-
}
|
|
206
|
-
else {
|
|
207
|
-
throw new HTTPResponseError(response);
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
217
|
//# sourceMappingURL=client.js.map
|
package/src/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/client.ts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EAAE,CAAC;IACX,gEAAgE;IAChE,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,GAAE,CAAC;IACxC,gEAAgE;IAChE,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,GAAE,CAAC;IACjC,cAAc,EAAE,IAAI;IACpB,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,CAAC;CACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TaskResult } from './task-result';
|
|
2
|
+
export declare class RunTasksResult {
|
|
3
|
+
readonly tasks: TaskResult[];
|
|
4
|
+
readonly completedTasks: TaskResult[];
|
|
5
|
+
readonly failedTasks: TaskResult[];
|
|
6
|
+
readonly completed: boolean;
|
|
7
|
+
readonly failed: boolean;
|
|
8
|
+
constructor(tasks: TaskResult[]);
|
|
9
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunTasksResult = void 0;
|
|
4
|
+
class RunTasksResult {
|
|
5
|
+
constructor(tasks) {
|
|
6
|
+
this.tasks = tasks;
|
|
7
|
+
this.completedTasks = tasks.filter((x) => x.hasCompleted);
|
|
8
|
+
this.failedTasks = tasks.filter((x) => !x.hasCompleted);
|
|
9
|
+
this.completed = this.failedTasks.length === 0;
|
|
10
|
+
this.failed = this.failedTasks.length > 0;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.RunTasksResult = RunTasksResult;
|
|
14
|
+
//# sourceMappingURL=run-tasks-result.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"run-tasks-result.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/run-tasks-result.ts"],"names":[],"mappings":";;;AAEA,MAAa,cAAc;IAOzB,YAA4B,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;QAC7C,IAAI,CAAC,cAAc,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAC1D,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;QAExD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC;IAC5C,CAAC;CACF;AAdD,wCAcC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task-result.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/task-result.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import { ChildProcess, SpawnOptionsWithoutStdio } from 'child_process';
|
|
4
|
+
import { WriteStream } from 'fs';
|
|
5
|
+
export interface SpawnAsyncOptions {
|
|
6
|
+
writeStream?: WriteStream;
|
|
7
|
+
dataCallback?: (data: string) => void;
|
|
8
|
+
errorCallback?: (data: string) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare function spawnAsync(command: string, args?: ReadonlyArray<string>, options?: SpawnOptionsWithoutStdio, logging?: SpawnAsyncOptions): Promise<ChildProcess>;
|
|
11
|
+
export declare function delay(ms: number): Promise<void>;
|
|
12
|
+
export declare function getTaskLogFilename(taskId: number): string;
|
|
13
|
+
export declare class HTTPResponseError extends Error {
|
|
14
|
+
readonly response: any;
|
|
15
|
+
constructor(response: any);
|
|
16
|
+
}
|
|
17
|
+
export declare const checkStatus: (response: any) => any;
|
package/src/lib/utils.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkStatus = exports.HTTPResponseError = exports.getTaskLogFilename = exports.delay = exports.spawnAsync = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const child_process_1 = require("child_process");
|
|
6
|
+
const readline_1 = require("readline");
|
|
7
|
+
const os_1 = require("os");
|
|
8
|
+
const path_1 = require("path");
|
|
9
|
+
function spawnAsync(command, args, options, logging) {
|
|
10
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
11
|
+
return new Promise((resolve, reject) => {
|
|
12
|
+
const childProcess = (0, child_process_1.spawn)(command, args, options);
|
|
13
|
+
if (logging.writeStream) {
|
|
14
|
+
childProcess.stdout.pipe(logging.writeStream);
|
|
15
|
+
childProcess.stderr.pipe(logging.writeStream);
|
|
16
|
+
}
|
|
17
|
+
if (logging.dataCallback) {
|
|
18
|
+
const readlineStdout = (0, readline_1.createInterface)({ input: childProcess.stdout });
|
|
19
|
+
readlineStdout.on('line', logging.dataCallback);
|
|
20
|
+
}
|
|
21
|
+
if (logging.errorCallback) {
|
|
22
|
+
const readlineStderr = (0, readline_1.createInterface)({ input: childProcess.stderr });
|
|
23
|
+
readlineStderr.on('line', logging.errorCallback);
|
|
24
|
+
}
|
|
25
|
+
childProcess.on('close', (code) => {
|
|
26
|
+
if (code === 0) {
|
|
27
|
+
resolve(childProcess);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
reject(childProcess);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
childProcess.on('error', (err) => {
|
|
34
|
+
reject(childProcess); // TODO: try to return error message
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
exports.spawnAsync = spawnAsync;
|
|
40
|
+
function delay(ms) {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
setTimeout(resolve, ms);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.delay = delay;
|
|
46
|
+
function getTaskLogFilename(taskId) {
|
|
47
|
+
return (0, path_1.join)((0, os_1.tmpdir)(), `task-${taskId}.log`);
|
|
48
|
+
}
|
|
49
|
+
exports.getTaskLogFilename = getTaskLogFilename;
|
|
50
|
+
class HTTPResponseError extends Error {
|
|
51
|
+
constructor(response) {
|
|
52
|
+
super(`HTTP Error Response: ${response.status} ${response.statusText}`);
|
|
53
|
+
this.response = response;
|
|
54
|
+
this.response = response;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.HTTPResponseError = HTTPResponseError;
|
|
58
|
+
const checkStatus = (response) => {
|
|
59
|
+
if (response.ok) {
|
|
60
|
+
// response.status >= 200 && response.status < 300
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
throw new HTTPResponseError(response);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.checkStatus = checkStatus;
|
|
68
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../libs/client/src/lib/utils.ts"],"names":[],"mappings":";;;;AAAA,iDAA8E;AAC9E,uCAA2C;AAE3C,2BAA4B;AAC5B,+BAA4B;AAQ5B,SAAsB,UAAU,CAC9B,OAAe,EACf,IAA4B,EAC5B,OAAkC,EAClC,OAA2B;;QAE3B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,MAAM,YAAY,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAEnD,IAAI,OAAO,CAAC,WAAW,EAAE;gBACvB,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;gBAC9C,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;aAC/C;YAED,IAAI,OAAO,CAAC,YAAY,EAAE;gBACxB,MAAM,cAAc,GAAG,IAAA,0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