@blaxel/core 0.2.4-dev4 → 0.2.4-preview.1

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.
@@ -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.processWithRetry();
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: {
@@ -1,135 +1,13 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.getAlphanumericLimitedHash = getAlphanumericLimitedHash;
4
7
  exports.getGlobalUniqueHash = getGlobalUniqueHash;
5
- // Pure JS MD5 implementation (public domain, compact)
6
- function md5(input) {
7
- function cmn(q, a, b, x, s, t) {
8
- a = (((a + q) | 0) + ((x + t) | 0)) | 0;
9
- return (((a << s) | (a >>> (32 - s))) + b) | 0;
10
- }
11
- function ff(a, b, c, d, x, s, t) {
12
- return cmn((b & c) | (~b & d), a, b, x, s, t);
13
- }
14
- function gg(a, b, c, d, x, s, t) {
15
- return cmn((b & d) | (c & ~d), a, b, x, s, t);
16
- }
17
- function hh(a, b, c, d, x, s, t) {
18
- return cmn(b ^ c ^ d, a, b, x, s, t);
19
- }
20
- function ii(a, b, c, d, x, s, t) {
21
- return cmn(c ^ (b | ~d), a, b, x, s, t);
22
- }
23
- function md5cycle(x, k) {
24
- let [a, b, c, d] = x;
25
- a = ff(a, b, c, d, k[0], 7, -680876936);
26
- d = ff(d, a, b, c, k[1], 12, -389564586);
27
- c = ff(c, d, a, b, k[2], 17, 606105819);
28
- b = ff(b, c, d, a, k[3], 22, -1044525330);
29
- a = ff(a, b, c, d, k[4], 7, -176418897);
30
- d = ff(d, a, b, c, k[5], 12, 1200080426);
31
- c = ff(c, d, a, b, k[6], 17, -1473231341);
32
- b = ff(b, c, d, a, k[7], 22, -45705983);
33
- a = ff(a, b, c, d, k[8], 7, 1770035416);
34
- d = ff(d, a, b, c, k[9], 12, -1958414417);
35
- c = ff(c, d, a, b, k[10], 17, -42063);
36
- b = ff(b, c, d, a, k[11], 22, -1990404162);
37
- a = ff(a, b, c, d, k[12], 7, 1804603682);
38
- d = ff(d, a, b, c, k[13], 12, -40341101);
39
- c = ff(c, d, a, b, k[14], 17, -1502002290);
40
- b = ff(b, c, d, a, k[15], 22, 1236535329);
41
- a = gg(a, b, c, d, k[1], 5, -165796510);
42
- d = gg(d, a, b, c, k[6], 9, -1069501632);
43
- c = gg(c, d, a, b, k[11], 14, 643717713);
44
- b = gg(b, c, d, a, k[0], 20, -373897302);
45
- a = gg(a, b, c, d, k[5], 5, -701558691);
46
- d = gg(d, a, b, c, k[10], 9, 38016083);
47
- c = gg(c, d, a, b, k[15], 14, -660478335);
48
- b = gg(b, c, d, a, k[4], 20, -405537848);
49
- a = gg(a, b, c, d, k[9], 5, 568446438);
50
- d = gg(d, a, b, c, k[14], 9, -1019803690);
51
- c = gg(c, d, a, b, k[3], 14, -187363961);
52
- b = gg(b, c, d, a, k[8], 20, 1163531501);
53
- a = gg(a, b, c, d, k[13], 5, -1444681467);
54
- d = gg(d, a, b, c, k[2], 9, -51403784);
55
- c = gg(c, d, a, b, k[7], 14, 1735328473);
56
- b = gg(b, c, d, a, k[12], 20, -1926607734);
57
- a = hh(a, b, c, d, k[5], 4, -378558);
58
- d = hh(d, a, b, c, k[8], 11, -2022574463);
59
- c = hh(c, d, a, b, k[11], 16, 1839030562);
60
- b = hh(b, c, d, a, k[14], 23, -35309556);
61
- a = hh(a, b, c, d, k[1], 4, -1530992060);
62
- d = hh(d, a, b, c, k[4], 11, 1272893353);
63
- c = hh(c, d, a, b, k[7], 16, -155497632);
64
- b = hh(b, c, d, a, k[10], 23, -1094730640);
65
- a = hh(a, b, c, d, k[13], 4, 681279174);
66
- d = hh(d, a, b, c, k[0], 11, -358537222);
67
- c = hh(c, d, a, b, k[3], 16, -722521979);
68
- b = hh(b, c, d, a, k[6], 23, 76029189);
69
- a = hh(a, b, c, d, k[9], 4, -640364487);
70
- d = hh(d, a, b, c, k[12], 11, -421815835);
71
- c = hh(c, d, a, b, k[15], 16, 530742520);
72
- b = hh(b, c, d, a, k[2], 23, -995338651);
73
- a = ii(a, b, c, d, k[0], 6, -198630844);
74
- d = ii(d, a, b, c, k[7], 10, 1126891415);
75
- c = ii(c, d, a, b, k[14], 15, -1416354905);
76
- b = ii(b, c, d, a, k[5], 21, -57434055);
77
- a = ii(a, b, c, d, k[12], 6, 1700485571);
78
- d = ii(d, a, b, c, k[3], 10, -1894986606);
79
- c = ii(c, d, a, b, k[10], 15, -1051523);
80
- b = ii(b, c, d, a, k[1], 21, -2054922799);
81
- a = ii(a, b, c, d, k[8], 6, 1873313359);
82
- d = ii(d, a, b, c, k[15], 10, -30611744);
83
- c = ii(c, d, a, b, k[6], 15, -1560198380);
84
- b = ii(b, c, d, a, k[13], 21, 1309151649);
85
- a = ii(a, b, c, d, k[4], 6, -145523070);
86
- d = ii(d, a, b, c, k[11], 10, -1120210379);
87
- c = ii(c, d, a, b, k[2], 15, 718787259);
88
- b = ii(b, c, d, a, k[9], 21, -343485551);
89
- x[0] = (a + x[0]) | 0;
90
- x[1] = (b + x[1]) | 0;
91
- x[2] = (c + x[2]) | 0;
92
- x[3] = (d + x[3]) | 0;
93
- }
94
- function md5blk(s) {
95
- const md5blks = [];
96
- for (let i = 0; i < 64; i += 4) {
97
- md5blks[i >> 2] =
98
- s.charCodeAt(i) +
99
- (s.charCodeAt(i + 1) << 8) +
100
- (s.charCodeAt(i + 2) << 16) +
101
- (s.charCodeAt(i + 3) << 24);
102
- }
103
- return md5blks;
104
- }
105
- function md51(s) {
106
- let n = s.length, state = [1732584193, -271733879, -1732584194, 271733878], i;
107
- for (i = 64; i <= n; i += 64) {
108
- md5cycle(state, md5blk(s.substring(i - 64, i)));
109
- }
110
- s = s.substring(i - 64);
111
- const tail = Array(16).fill(0);
112
- for (i = 0; i < s.length; i++)
113
- tail[i >> 2] |= s.charCodeAt(i) << ((i % 4) << 3);
114
- tail[i >> 2] |= 0x80 << ((i % 4) << 3);
115
- if (i > 55) {
116
- md5cycle(state, tail);
117
- tail.fill(0);
118
- }
119
- tail[14] = n * 8;
120
- md5cycle(state, tail);
121
- return state;
122
- }
123
- function rhex(n) {
124
- let s = '', j = 0;
125
- for (; j < 4; j++)
126
- s += ('0' + ((n >> (j * 8 + 4)) & 0x0f).toString(16)).slice(-2) + ((n >> (j * 8)) & 0x0f).toString(16);
127
- return s;
128
- }
129
- return md51(input).map(rhex).join('');
130
- }
8
+ const crypto_1 = __importDefault(require("crypto"));
131
9
  function getAlphanumericLimitedHash(input, maxSize = 48) {
132
- const hash = md5(input);
10
+ const hash = crypto_1.default.createHash('md5').update(input).digest('hex');
133
11
  return hash.length > maxSize ? hash.substring(0, maxSize) : hash;
134
12
  }
135
13
  function getGlobalUniqueHash(workspace, type, name) {
@@ -1,3 +1 @@
1
1
  export * from "./jobs.js";
2
- export * from "./start.js";
3
- export * from "./types.js";
@@ -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);
@@ -1,13 +1,11 @@
1
1
  declare class BlJob {
2
- jobName: string;
3
- constructor(jobName: string);
4
- get fallbackUrl(): import("url").URL | null;
5
- get externalUrl(): import("url").URL;
6
- get internalUrl(): import("url").URL;
7
- get forcedUrl(): import("url").URL | null;
8
- get url(): import("url").URL;
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: (jobName: string) => 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
- jobName;
11
- constructor(jobName) {
12
- this.jobName = jobName;
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
- return null;
19
- }
20
- get externalUrl() {
21
- return new URL(`${settings_js_1.settings.runUrl}/${settings_js_1.settings.workspace}/jobs/${this.jobName}`);
22
- }
23
- get internalUrl() {
24
- const hash = (0, internal_js_1.getGlobalUniqueHash)(settings_js_1.settings.workspace, "job", this.jobName);
25
- return new URL(`${settings_js_1.settings.runInternalProtocol}://bl-${settings_js_1.settings.env}-${hash}.${settings_js_1.settings.runInternalHostname}`);
26
- }
27
- get forcedUrl() {
28
- const envVar = this.jobName.replace(/-/g, "_").toUpperCase();
29
- if (env_js_1.env[`BL_JOB_${envVar}_URL`]) {
30
- return new URL(env_js_1.env[`BL_JOB_${envVar}_URL`]);
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 null;
32
+ return result;
33
33
  }
34
- get url() {
35
- if (this.forcedUrl)
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
- async call(url, tasks) {
42
- let body = {
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
- async run(tasks) {
56
- logger_js_1.logger.debug(`Job Calling: ${this.jobName}`);
57
- const span = (0, telemetry_js_1.startSpan)(this.jobName, {
58
- attributes: {
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 response = await this.call(this.url, tasks);
66
- return await response.text();
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
- finally {
88
- span.end();
49
+ catch (error) {
50
+ console.error('Job execution failed:', error);
51
+ process.exit(1);
89
52
  }
90
53
  }
91
54
  }
92
- const blJob = (jobName) => {
93
- return new BlJob(jobName);
94
- };
95
- exports.blJob = blJob;
55
+ exports.blJob = new BlJob();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.4-dev4",
3
+ "version": "0.2.4-preview.1",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",
@@ -66,19 +66,13 @@
66
66
  },
67
67
  "devDependencies": {
68
68
  "@eslint/js": "^9.26.0",
69
- "@testing-library/dom": "^9.3.0",
70
69
  "@types/ws": "^8.18.1",
71
- "jsdom": "^26.1.0",
72
70
  "typescript": "^5.0.0",
73
- "typescript-eslint": "^8.31.1",
74
- "vite": "^5.2.0",
75
- "vitest": "^1.5.0"
71
+ "typescript-eslint": "^8.31.1"
76
72
  },
77
73
  "scripts": {
78
74
  "lint": "eslint src/",
79
75
  "dev": "tsc --watch",
80
- "build": "tsc",
81
- "test": "vitest --run",
82
- "test:watch": "vitest --watch"
76
+ "build": "tsc"
83
77
  }
84
78
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vitest_1 = require("vitest");
4
- const internal_1 = require("./internal");
5
- (0, vitest_1.describe)('getAlphanumericLimitedHash', () => {
6
- (0, vitest_1.it)('returns correct MD5 hash for a known string', () => {
7
- // MD5 of 'hello' is 5d41402abc4b2a76b9719d911017c592
8
- (0, vitest_1.expect)((0, internal_1.getAlphanumericLimitedHash)('hello')).toBe('05d04104002a0bc04b02a0760b907109d0910100170c5092');
9
- });
10
- (0, vitest_1.it)('respects the maxSize parameter', () => {
11
- const hash = (0, internal_1.getAlphanumericLimitedHash)('hello', 8);
12
- (0, vitest_1.expect)(hash.length).toBe(8);
13
- (0, vitest_1.expect)(hash).toBe('05d04104');
14
- });
15
- (0, vitest_1.it)('returns full hash if maxSize is larger than hash', () => {
16
- const hash = (0, internal_1.getAlphanumericLimitedHash)('hello', 64);
17
- (0, vitest_1.expect)(hash).toBe('05d04104002a0bc04b02a0760b907109d0910100170c5092');
18
- });
19
- });
20
- (0, vitest_1.describe)('getGlobalUniqueHash', () => {
21
- (0, vitest_1.it)('returns a hash for the combined workspace, type, and name', () => {
22
- // The input string will be 'ws-type-name'
23
- const expected = (0, internal_1.getAlphanumericLimitedHash)('ws-type-name', 48);
24
- (0, vitest_1.expect)((0, internal_1.getGlobalUniqueHash)('ws', 'type', 'name')).toBe(expected);
25
- });
26
- (0, vitest_1.it)('returns a 48-character hash by default', () => {
27
- const hash = (0, internal_1.getGlobalUniqueHash)('a', 'b', 'c');
28
- (0, vitest_1.expect)(hash.length).toBeLessThanOrEqual(48);
29
- });
30
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- const vitest_1 = require("vitest");
37
- // Import your SDK entry point or a function to test
38
- const sdk = __importStar(require("./index"));
39
- (0, vitest_1.describe)('SDK Browser Integration', () => {
40
- (0, vitest_1.it)('should load the SDK without Node.js-only modules', () => {
41
- // Example: check that SDK loads and a function exists
42
- (0, vitest_1.expect)(typeof sdk).toBe('object');
43
- // Add more specific tests for your SDK as needed
44
- });
45
- });
@@ -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 {};
@@ -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();
@@ -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();
@@ -1 +0,0 @@
1
- export declare const blStartJob: (func: (args: any) => Promise<void>) => void;
@@ -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;
@@ -1,3 +0,0 @@
1
- export type ExecutionArgs = {
2
- [key: number]: any;
3
- }[];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });