@blaxel/core 0.2.4-dev4 → 0.2.4-preview.2
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/dist/authentication/clientcredentials.d.ts +0 -2
- package/dist/authentication/clientcredentials.js +1 -16
- package/dist/jobs/index.d.ts +0 -2
- package/dist/jobs/index.js +0 -2
- package/dist/jobs/jobs.d.ts +8 -10
- package/dist/jobs/jobs.js +40 -80
- package/package.json +1 -1
- package/dist/jobs/batches.d.ts +0 -32
- package/dist/jobs/batches.js +0 -40
- package/dist/jobs/job.d.ts +0 -33
- package/dist/jobs/job.js +0 -51
- package/dist/jobs/start.d.ts +0 -1
- package/dist/jobs/start.js +0 -59
- package/dist/jobs/types.d.ts +0 -3
- package/dist/jobs/types.js +0 -2
|
@@ -9,8 +9,6 @@ export declare class ClientCredentials extends Credentials {
|
|
|
9
9
|
get workspace(): string;
|
|
10
10
|
needRefresh(): boolean;
|
|
11
11
|
authenticate(): Promise<void>;
|
|
12
|
-
private sleep;
|
|
13
|
-
processWithRetry(retry?: number): Promise<void>;
|
|
14
12
|
process(): Promise<void>;
|
|
15
13
|
get authorization(): string;
|
|
16
14
|
get token(): string;
|
|
@@ -42,24 +42,9 @@ class ClientCredentials extends credentials_js_1.Credentials {
|
|
|
42
42
|
if (!this.needRefresh()) {
|
|
43
43
|
return this.currentPromise || Promise.resolve();
|
|
44
44
|
}
|
|
45
|
-
this.currentPromise = this.
|
|
45
|
+
this.currentPromise = this.process();
|
|
46
46
|
return this.currentPromise;
|
|
47
47
|
}
|
|
48
|
-
sleep(ms) {
|
|
49
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
50
|
-
}
|
|
51
|
-
async processWithRetry(retry = 3) {
|
|
52
|
-
try {
|
|
53
|
-
return await this.process();
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
if (retry > 0) {
|
|
57
|
-
await this.sleep(1000);
|
|
58
|
-
return this.processWithRetry(retry - 1);
|
|
59
|
-
}
|
|
60
|
-
throw error;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
48
|
async process() {
|
|
64
49
|
const response = await (0, authentication_js_1.oauthToken)({
|
|
65
50
|
headers: {
|
package/dist/jobs/index.d.ts
CHANGED
package/dist/jobs/index.js
CHANGED
|
@@ -15,5 +15,3 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./jobs.js"), exports);
|
|
18
|
-
__exportStar(require("./start.js"), exports);
|
|
19
|
-
__exportStar(require("./types.js"), exports);
|
package/dist/jobs/jobs.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
declare class BlJob {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
get
|
|
7
|
-
get
|
|
8
|
-
|
|
9
|
-
call(url: URL, tasks: Record<string, unknown>[]): Promise<Response>;
|
|
10
|
-
run(tasks: Record<string, unknown>[]): Promise<string>;
|
|
2
|
+
getArguments(): Promise<{
|
|
3
|
+
[key: number]: any;
|
|
4
|
+
}>;
|
|
5
|
+
private parseCommandLineArgs;
|
|
6
|
+
get indexKey(): string;
|
|
7
|
+
get index(): number;
|
|
8
|
+
start(func: (args: any) => Promise<void>): Promise<void>;
|
|
11
9
|
}
|
|
12
|
-
export declare const blJob:
|
|
10
|
+
export declare const blJob: BlJob;
|
|
13
11
|
export {};
|
package/dist/jobs/jobs.js
CHANGED
|
@@ -2,94 +2,54 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.blJob = void 0;
|
|
4
4
|
const env_js_1 = require("../common/env.js");
|
|
5
|
-
const internal_js_1 = require("../common/internal.js");
|
|
6
|
-
const logger_js_1 = require("../common/logger.js");
|
|
7
|
-
const settings_js_1 = require("../common/settings.js");
|
|
8
|
-
const telemetry_js_1 = require("../telemetry/telemetry.js");
|
|
9
5
|
class BlJob {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
get fallbackUrl() {
|
|
15
|
-
if (this.externalUrl != this.url) {
|
|
16
|
-
return this.externalUrl;
|
|
6
|
+
async getArguments() {
|
|
7
|
+
if (!env_js_1.env.BL_EXECUTION_DATA_URL) {
|
|
8
|
+
const args = this.parseCommandLineArgs();
|
|
9
|
+
return args;
|
|
17
10
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
11
|
+
const response = await fetch(env_js_1.env.BL_EXECUTION_DATA_URL);
|
|
12
|
+
const data = await response.json();
|
|
13
|
+
return data.tasks[this.index] ?? {};
|
|
14
|
+
}
|
|
15
|
+
parseCommandLineArgs() {
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
const result = {};
|
|
18
|
+
for (let i = 0; i < args.length; i++) {
|
|
19
|
+
const arg = args[i];
|
|
20
|
+
if (arg.startsWith('--')) {
|
|
21
|
+
const key = arg.slice(2);
|
|
22
|
+
const value = args[i + 1];
|
|
23
|
+
if (value && !value.startsWith('--')) {
|
|
24
|
+
result[key] = value;
|
|
25
|
+
i++;
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
result[key] = 'true';
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return result;
|
|
33
33
|
}
|
|
34
|
-
get
|
|
35
|
-
|
|
36
|
-
return this.forcedUrl;
|
|
37
|
-
if (settings_js_1.settings.runInternalHostname)
|
|
38
|
-
return this.internalUrl;
|
|
39
|
-
return this.externalUrl;
|
|
34
|
+
get indexKey() {
|
|
35
|
+
return env_js_1.env.BL_TASK_KEY ?? "TASK_INDEX";
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
tasks: tasks
|
|
44
|
-
};
|
|
45
|
-
const response = await fetch(url + "/executions", {
|
|
46
|
-
method: "POST",
|
|
47
|
-
headers: {
|
|
48
|
-
...settings_js_1.settings.headers,
|
|
49
|
-
"Content-Type": "application/json",
|
|
50
|
-
},
|
|
51
|
-
body: JSON.stringify(body),
|
|
52
|
-
});
|
|
53
|
-
return response;
|
|
37
|
+
get index() {
|
|
38
|
+
return env_js_1.env[this.indexKey] ? Number(env_js_1.env[this.indexKey]) ?? 0 : 0;
|
|
54
39
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"job.name": this.jobName,
|
|
60
|
-
"span.type": "job.run",
|
|
61
|
-
},
|
|
62
|
-
isRoot: false,
|
|
63
|
-
});
|
|
40
|
+
/*
|
|
41
|
+
Run a job defined in a function, it's run in the current process
|
|
42
|
+
*/
|
|
43
|
+
async start(func) {
|
|
64
44
|
try {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
catch (err) {
|
|
69
|
-
if (err instanceof Error) {
|
|
70
|
-
if (!this.fallbackUrl) {
|
|
71
|
-
span.setAttribute("job.run.error", err.stack);
|
|
72
|
-
throw err;
|
|
73
|
-
}
|
|
74
|
-
try {
|
|
75
|
-
const response = await this.call(this.fallbackUrl, tasks);
|
|
76
|
-
return await response.text();
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
if (err instanceof Error) {
|
|
80
|
-
span.setAttribute("job.run.error", err.stack);
|
|
81
|
-
}
|
|
82
|
-
throw err;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
throw err;
|
|
45
|
+
const parsedArgs = await this.getArguments();
|
|
46
|
+
await func(parsedArgs);
|
|
47
|
+
process.exit(0);
|
|
86
48
|
}
|
|
87
|
-
|
|
88
|
-
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('Job execution failed:', error);
|
|
51
|
+
process.exit(1);
|
|
89
52
|
}
|
|
90
53
|
}
|
|
91
54
|
}
|
|
92
|
-
|
|
93
|
-
return new BlJob(jobName);
|
|
94
|
-
};
|
|
95
|
-
exports.blJob = blJob;
|
|
55
|
+
exports.blJob = new BlJob();
|
package/package.json
CHANGED
package/dist/jobs/batches.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
declare class BlBatch {
|
|
2
|
-
/**
|
|
3
|
-
* Lists all remote batch jobs for a given name
|
|
4
|
-
* @param name - The name of the job to list
|
|
5
|
-
*/
|
|
6
|
-
list(name: string): void;
|
|
7
|
-
/**
|
|
8
|
-
* Creates a new remote batch job configuration.
|
|
9
|
-
* This is used for remote execution management, not for local execution.
|
|
10
|
-
* @param name - The name of the job
|
|
11
|
-
* @param args - Array of argument arrays for each job in the batch
|
|
12
|
-
* @returns The batch configuration object
|
|
13
|
-
*/
|
|
14
|
-
create(name: string, args: any[][]): {
|
|
15
|
-
name: string;
|
|
16
|
-
args: any[][];
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Kills a remote batch job
|
|
20
|
-
* @param name - The name of the job
|
|
21
|
-
* @param batchId - The ID of the batch to kill
|
|
22
|
-
*/
|
|
23
|
-
kill(name: string, batchId: string): void;
|
|
24
|
-
/**
|
|
25
|
-
* Retrieves information about a remote batch job
|
|
26
|
-
* @param name - The name of the job
|
|
27
|
-
* @param batchId - The ID of the batch to get information for
|
|
28
|
-
*/
|
|
29
|
-
get(name: string, batchId: string): void;
|
|
30
|
-
}
|
|
31
|
-
export declare const blBatch: BlBatch;
|
|
32
|
-
export {};
|
package/dist/jobs/batches.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.blBatch = void 0;
|
|
4
|
-
class BlBatch {
|
|
5
|
-
/**
|
|
6
|
-
* Lists all remote batch jobs for a given name
|
|
7
|
-
* @param name - The name of the job to list
|
|
8
|
-
*/
|
|
9
|
-
list(name) {
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new remote batch job configuration.
|
|
13
|
-
* This is used for remote execution management, not for local execution.
|
|
14
|
-
* @param name - The name of the job
|
|
15
|
-
* @param args - Array of argument arrays for each job in the batch
|
|
16
|
-
* @returns The batch configuration object
|
|
17
|
-
*/
|
|
18
|
-
create(name, args) {
|
|
19
|
-
const batch = {
|
|
20
|
-
name,
|
|
21
|
-
args,
|
|
22
|
-
};
|
|
23
|
-
return batch;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Kills a remote batch job
|
|
27
|
-
* @param name - The name of the job
|
|
28
|
-
* @param batchId - The ID of the batch to kill
|
|
29
|
-
*/
|
|
30
|
-
kill(name, batchId) {
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Retrieves information about a remote batch job
|
|
34
|
-
* @param name - The name of the job
|
|
35
|
-
* @param batchId - The ID of the batch to get information for
|
|
36
|
-
*/
|
|
37
|
-
get(name, batchId) {
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.blBatch = new BlBatch();
|
package/dist/jobs/job.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
declare class BlJob {
|
|
2
|
-
start(func: (...args: any[]) => Promise<void>): void;
|
|
3
|
-
/**
|
|
4
|
-
* Lists all remote batch jobs for a given name
|
|
5
|
-
* @param name - The name of the job to list
|
|
6
|
-
*/
|
|
7
|
-
list(name: string): void;
|
|
8
|
-
/**
|
|
9
|
-
* Creates a new remote batch job configuration.
|
|
10
|
-
* This is used for remote execution management, not for local execution.
|
|
11
|
-
* @param name - The name of the job
|
|
12
|
-
* @param args - Array of argument arrays for each job in the batch
|
|
13
|
-
* @returns The batch configuration object
|
|
14
|
-
*/
|
|
15
|
-
create(name: string, args: any[][]): {
|
|
16
|
-
name: string;
|
|
17
|
-
args: any[][];
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Kills a remote batch job
|
|
21
|
-
* @param name - The name of the job
|
|
22
|
-
* @param batchId - The ID of the batch to kill
|
|
23
|
-
*/
|
|
24
|
-
kill(name: string, batchId: string): void;
|
|
25
|
-
/**
|
|
26
|
-
* Retrieves information about a remote batch job
|
|
27
|
-
* @param name - The name of the job
|
|
28
|
-
* @param batchId - The ID of the batch to get information for
|
|
29
|
-
*/
|
|
30
|
-
get(name: string, batchId: string): void;
|
|
31
|
-
}
|
|
32
|
-
export declare const blJob: BlJob;
|
|
33
|
-
export {};
|
package/dist/jobs/job.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.blJob = void 0;
|
|
4
|
-
function retrieveArguments() {
|
|
5
|
-
const args = process.argv.slice(2);
|
|
6
|
-
return args;
|
|
7
|
-
}
|
|
8
|
-
class BlJob {
|
|
9
|
-
/*
|
|
10
|
-
Run a job defined in a function, it's run in the current process
|
|
11
|
-
*/
|
|
12
|
-
start(func) {
|
|
13
|
-
const args = retrieveArguments();
|
|
14
|
-
func(...args);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Lists all remote batch jobs for a given name
|
|
18
|
-
* @param name - The name of the job to list
|
|
19
|
-
*/
|
|
20
|
-
list(name) {
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Creates a new remote batch job configuration.
|
|
24
|
-
* This is used for remote execution management, not for local execution.
|
|
25
|
-
* @param name - The name of the job
|
|
26
|
-
* @param args - Array of argument arrays for each job in the batch
|
|
27
|
-
* @returns The batch configuration object
|
|
28
|
-
*/
|
|
29
|
-
create(name, args) {
|
|
30
|
-
const batch = {
|
|
31
|
-
name,
|
|
32
|
-
args,
|
|
33
|
-
};
|
|
34
|
-
return batch;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Kills a remote batch job
|
|
38
|
-
* @param name - The name of the job
|
|
39
|
-
* @param batchId - The ID of the batch to kill
|
|
40
|
-
*/
|
|
41
|
-
kill(name, batchId) {
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Retrieves information about a remote batch job
|
|
45
|
-
* @param name - The name of the job
|
|
46
|
-
* @param batchId - The ID of the batch to get information for
|
|
47
|
-
*/
|
|
48
|
-
get(name, batchId) {
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.blJob = new BlJob();
|
package/dist/jobs/start.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const blStartJob: (func: (args: any) => Promise<void>) => void;
|
package/dist/jobs/start.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.blStartJob = void 0;
|
|
4
|
-
const env_js_1 = require("../common/env.js");
|
|
5
|
-
class BlJobWrapper {
|
|
6
|
-
async getArguments() {
|
|
7
|
-
if (!env_js_1.env.BL_EXECUTION_DATA_URL) {
|
|
8
|
-
const args = this.parseCommandLineArgs();
|
|
9
|
-
return args;
|
|
10
|
-
}
|
|
11
|
-
const response = await fetch(env_js_1.env.BL_EXECUTION_DATA_URL);
|
|
12
|
-
const data = await response.json();
|
|
13
|
-
return data.tasks[this.index] ?? {};
|
|
14
|
-
}
|
|
15
|
-
parseCommandLineArgs() {
|
|
16
|
-
const args = process.argv.slice(2);
|
|
17
|
-
const result = {};
|
|
18
|
-
for (let i = 0; i < args.length; i++) {
|
|
19
|
-
const arg = args[i];
|
|
20
|
-
if (arg.startsWith('--')) {
|
|
21
|
-
const key = arg.slice(2);
|
|
22
|
-
const value = args[i + 1];
|
|
23
|
-
if (value && !value.startsWith('--')) {
|
|
24
|
-
result[key] = value;
|
|
25
|
-
i++;
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
result[key] = 'true';
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
get indexKey() {
|
|
35
|
-
return env_js_1.env.BL_TASK_KEY ?? "TASK_INDEX";
|
|
36
|
-
}
|
|
37
|
-
get index() {
|
|
38
|
-
return env_js_1.env[this.indexKey] ? Number(env_js_1.env[this.indexKey]) ?? 0 : 0;
|
|
39
|
-
}
|
|
40
|
-
/*
|
|
41
|
-
Run a job defined in a function, it's run in the current process
|
|
42
|
-
*/
|
|
43
|
-
async start(func) {
|
|
44
|
-
try {
|
|
45
|
-
const parsedArgs = await this.getArguments();
|
|
46
|
-
await func(parsedArgs);
|
|
47
|
-
process.exit(0);
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
console.error('Job execution failed:', error);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const blStartJob = (func) => {
|
|
56
|
-
const job = new BlJobWrapper();
|
|
57
|
-
job.start(func);
|
|
58
|
-
};
|
|
59
|
-
exports.blStartJob = blStartJob;
|
package/dist/jobs/types.d.ts
DELETED
package/dist/jobs/types.js
DELETED