@constructive-io/knative-job-service 0.4.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.md +12 -0
- package/LICENSE +23 -0
- package/README.md +1 -0
- package/dist/env.d.ts +17 -0
- package/dist/env.js +20 -0
- package/dist/index.d.ts +0 -0
- package/dist/index.js +2 -0
- package/dist/run.d.ts +7 -0
- package/dist/run.js +84 -0
- package/jest.config.js +18 -0
- package/package.json +48 -0
- package/src/index.ts +1 -0
- package/src/run.ts +94 -0
- package/tsconfig.esm.json +9 -0
- package/tsconfig.json +9 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 0.4.9 (2025-12-18)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @constructive-io/knative-job-service
|
|
9
|
+
|
|
10
|
+
## [0.4.8](https://github.com/constructive-io/jobs/compare/@launchql/knative-job-service@0.4.7...@launchql/knative-job-service@0.4.8) (2025-12-17)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @launchql/knative-job-service
|
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
Copyright (c) 2025 Constructive <developers@constructive.io>
|
|
5
|
+
Copyright (c) 2020-present, Interweb, Inc.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# knative-job-service
|
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare const _default: Readonly<{
|
|
2
|
+
PGUSER: string;
|
|
3
|
+
PGHOST: string;
|
|
4
|
+
PGPASSWORD: string;
|
|
5
|
+
PGPORT: number;
|
|
6
|
+
PGDATABASE: string;
|
|
7
|
+
JOBS_SCHEMA: string;
|
|
8
|
+
JOBS_SUPPORT_ANY: boolean;
|
|
9
|
+
JOBS_SUPPORTED: string[];
|
|
10
|
+
HOSTNAME: string;
|
|
11
|
+
INTERNAL_GATEWAY_URL: string;
|
|
12
|
+
INTERNAL_JOBS_CALLBACK_URL: string;
|
|
13
|
+
INTERNAL_JOBS_CALLBACK_PORT: number;
|
|
14
|
+
}> & import("envalid").CleanEnv & {
|
|
15
|
+
readonly [varName: string]: string;
|
|
16
|
+
};
|
|
17
|
+
export default _default;
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const envalid_1 = require("envalid");
|
|
4
|
+
const array = (0, envalid_1.makeValidator)((x) => x.split(',').filter((i) => i), '');
|
|
5
|
+
exports.default = (0, envalid_1.cleanEnv)(process.env, {
|
|
6
|
+
PGUSER: (0, envalid_1.str)({ default: 'postgres' }),
|
|
7
|
+
PGHOST: (0, envalid_1.str)({ default: 'localhost' }),
|
|
8
|
+
PGPASSWORD: (0, envalid_1.str)({ default: 'password' }),
|
|
9
|
+
PGPORT: (0, envalid_1.port)({ default: 5432 }),
|
|
10
|
+
PGDATABASE: (0, envalid_1.str)({ default: 'jobs' }),
|
|
11
|
+
JOBS_SCHEMA: (0, envalid_1.str)({ default: 'app_jobs' }),
|
|
12
|
+
JOBS_SUPPORT_ANY: (0, envalid_1.bool)({ default: true }),
|
|
13
|
+
JOBS_SUPPORTED: array({ default: '' }),
|
|
14
|
+
HOSTNAME: (0, envalid_1.str)({
|
|
15
|
+
default: 'worker-0'
|
|
16
|
+
}),
|
|
17
|
+
INTERNAL_GATEWAY_URL: (0, envalid_1.url)(),
|
|
18
|
+
INTERNAL_JOBS_CALLBACK_URL: (0, envalid_1.url)(),
|
|
19
|
+
INTERNAL_JOBS_CALLBACK_PORT: (0, envalid_1.port)({ default: 12345 })
|
|
20
|
+
}, { dotEnvPath: null });
|
package/dist/index.d.ts
ADDED
|
File without changes
|
package/dist/index.js
ADDED
package/dist/run.d.ts
ADDED
package/dist/run.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.bootJobs = exports.waitForJobsPrereqs = exports.startJobsServices = void 0;
|
|
8
|
+
const job_scheduler_1 = __importDefault(require("@constructive-io/job-scheduler"));
|
|
9
|
+
const knative_job_worker_1 = __importDefault(require("@constructive-io/knative-job-worker"));
|
|
10
|
+
const knative_job_server_1 = __importDefault(require("@constructive-io/knative-job-server"));
|
|
11
|
+
const job_pg_1 = __importDefault(require("@constructive-io/job-pg"));
|
|
12
|
+
const pg_1 = require("pg");
|
|
13
|
+
const async_retry_1 = __importDefault(require("async-retry"));
|
|
14
|
+
const job_utils_1 = require("@constructive-io/job-utils");
|
|
15
|
+
const startJobsServices = () => {
|
|
16
|
+
// eslint-disable-next-line no-console
|
|
17
|
+
console.log('starting jobs services...');
|
|
18
|
+
const pgPool = job_pg_1.default.getPool();
|
|
19
|
+
const app = (0, knative_job_server_1.default)(pgPool);
|
|
20
|
+
const callbackPort = (0, job_utils_1.getJobsCallbackPort)();
|
|
21
|
+
const httpServer = app.listen(callbackPort, () => {
|
|
22
|
+
// eslint-disable-next-line no-console
|
|
23
|
+
console.log(`[cb] listening ON ${callbackPort}`);
|
|
24
|
+
const tasks = (0, job_utils_1.getJobSupported)();
|
|
25
|
+
const worker = new knative_job_worker_1.default({
|
|
26
|
+
pgPool,
|
|
27
|
+
workerId: (0, job_utils_1.getWorkerHostname)(),
|
|
28
|
+
tasks
|
|
29
|
+
});
|
|
30
|
+
const scheduler = new job_scheduler_1.default({
|
|
31
|
+
pgPool,
|
|
32
|
+
workerId: (0, job_utils_1.getSchedulerHostname)(),
|
|
33
|
+
tasks
|
|
34
|
+
});
|
|
35
|
+
worker.listen();
|
|
36
|
+
scheduler.listen();
|
|
37
|
+
});
|
|
38
|
+
return { pgPool, httpServer };
|
|
39
|
+
};
|
|
40
|
+
exports.startJobsServices = startJobsServices;
|
|
41
|
+
const waitForJobsPrereqs = async () => {
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.log('waiting for jobs prereqs');
|
|
44
|
+
let client = null;
|
|
45
|
+
try {
|
|
46
|
+
const cfg = (0, job_utils_1.getJobPgConfig)();
|
|
47
|
+
client = new pg_1.Client({
|
|
48
|
+
host: cfg.host,
|
|
49
|
+
port: cfg.port,
|
|
50
|
+
user: cfg.user,
|
|
51
|
+
password: cfg.password,
|
|
52
|
+
database: cfg.database
|
|
53
|
+
});
|
|
54
|
+
await client.connect();
|
|
55
|
+
const schema = (0, job_utils_1.getJobSchema)();
|
|
56
|
+
await client.query(`SELECT * FROM "${schema}".jobs LIMIT 1;`);
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.log(error);
|
|
61
|
+
throw new Error('jobs server boot failed...');
|
|
62
|
+
}
|
|
63
|
+
finally {
|
|
64
|
+
if (client) {
|
|
65
|
+
void client.end();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
exports.waitForJobsPrereqs = waitForJobsPrereqs;
|
|
70
|
+
const bootJobs = async () => {
|
|
71
|
+
// eslint-disable-next-line no-console
|
|
72
|
+
console.log('attempting to boot jobs');
|
|
73
|
+
await (0, async_retry_1.default)(async () => {
|
|
74
|
+
await (0, exports.waitForJobsPrereqs)();
|
|
75
|
+
}, {
|
|
76
|
+
retries: 10,
|
|
77
|
+
factor: 2
|
|
78
|
+
});
|
|
79
|
+
(0, exports.startJobsServices)();
|
|
80
|
+
};
|
|
81
|
+
exports.bootJobs = bootJobs;
|
|
82
|
+
if (require.main === module) {
|
|
83
|
+
void (0, exports.bootJobs)();
|
|
84
|
+
}
|
package/jest.config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @type {import('ts-jest').JestConfigWithTsJest} */
|
|
2
|
+
module.exports = {
|
|
3
|
+
preset: 'ts-jest',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
transform: {
|
|
6
|
+
'^.+\\.tsx?$': [
|
|
7
|
+
'ts-jest',
|
|
8
|
+
{
|
|
9
|
+
babelConfig: false,
|
|
10
|
+
tsconfig: 'tsconfig.json',
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
},
|
|
14
|
+
transformIgnorePatterns: [`/node_modules/*`],
|
|
15
|
+
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
|
|
16
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
|
|
17
|
+
modulePathIgnorePatterns: ['dist/*'],
|
|
18
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@constructive-io/knative-job-service",
|
|
3
|
+
"version": "0.4.9",
|
|
4
|
+
"description": "knative job service",
|
|
5
|
+
"author": "Constructive <developers@constructive.io>",
|
|
6
|
+
"homepage": "https://github.com/constructive-io/jobs/tree/master/packages/knative-job-service#readme",
|
|
7
|
+
"license": "SEE LICENSE IN LICENSE",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"directories": {
|
|
10
|
+
"lib": "src",
|
|
11
|
+
"test": "__tests__"
|
|
12
|
+
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"faas-job-service": "src/run.ts"
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "https://github.com/constructive-io/jobs"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc -p tsconfig.json",
|
|
25
|
+
"build:watch": "tsc -p tsconfig.json -w",
|
|
26
|
+
"start": "node dist/run.js",
|
|
27
|
+
"dev": "ts-node --transpile-only src/run.ts",
|
|
28
|
+
"test": "jest",
|
|
29
|
+
"test:watch": "jest --watch",
|
|
30
|
+
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/constructive-io/jobs/issues"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"ts-node": "^10.9.2"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"@constructive-io/job-pg": "^0.3.5",
|
|
40
|
+
"@constructive-io/job-scheduler": "^0.3.7",
|
|
41
|
+
"@constructive-io/job-utils": "^0.5.0",
|
|
42
|
+
"@constructive-io/knative-job-server": "^0.3.7",
|
|
43
|
+
"@constructive-io/knative-job-worker": "^0.5.9",
|
|
44
|
+
"async-retry": "1.3.1",
|
|
45
|
+
"pg": "8.16.3"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "86d74dc4fce9051df0d2b5bcc163607aba42f009"
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
// noop
|
package/src/run.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import Scheduler from '@constructive-io/job-scheduler';
|
|
4
|
+
import Worker from '@constructive-io/knative-job-worker';
|
|
5
|
+
import server from '@constructive-io/knative-job-server';
|
|
6
|
+
import poolManager from '@constructive-io/job-pg';
|
|
7
|
+
import { Client } from 'pg';
|
|
8
|
+
import retry from 'async-retry';
|
|
9
|
+
import {
|
|
10
|
+
getJobPgConfig,
|
|
11
|
+
getJobSchema,
|
|
12
|
+
getSchedulerHostname,
|
|
13
|
+
getWorkerHostname,
|
|
14
|
+
getJobSupported,
|
|
15
|
+
getJobsCallbackPort,
|
|
16
|
+
} from '@constructive-io/job-utils';
|
|
17
|
+
|
|
18
|
+
export const startJobsServices = () => {
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.log('starting jobs services...');
|
|
21
|
+
const pgPool = poolManager.getPool();
|
|
22
|
+
const app = server(pgPool);
|
|
23
|
+
|
|
24
|
+
const callbackPort = getJobsCallbackPort();
|
|
25
|
+
const httpServer = app.listen(callbackPort, () => {
|
|
26
|
+
// eslint-disable-next-line no-console
|
|
27
|
+
console.log(`[cb] listening ON ${callbackPort}`);
|
|
28
|
+
|
|
29
|
+
const tasks = getJobSupported();
|
|
30
|
+
|
|
31
|
+
const worker = new Worker({
|
|
32
|
+
pgPool,
|
|
33
|
+
workerId: getWorkerHostname(),
|
|
34
|
+
tasks
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const scheduler = new Scheduler({
|
|
38
|
+
pgPool,
|
|
39
|
+
workerId: getSchedulerHostname(),
|
|
40
|
+
tasks
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
worker.listen();
|
|
44
|
+
scheduler.listen();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
return { pgPool, httpServer };
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const waitForJobsPrereqs = async (): Promise<void> => {
|
|
51
|
+
// eslint-disable-next-line no-console
|
|
52
|
+
console.log('waiting for jobs prereqs');
|
|
53
|
+
let client: Client | null = null;
|
|
54
|
+
try {
|
|
55
|
+
const cfg = getJobPgConfig();
|
|
56
|
+
client = new Client({
|
|
57
|
+
host: cfg.host,
|
|
58
|
+
port: cfg.port,
|
|
59
|
+
user: cfg.user,
|
|
60
|
+
password: cfg.password,
|
|
61
|
+
database: cfg.database
|
|
62
|
+
});
|
|
63
|
+
await client.connect();
|
|
64
|
+
const schema = getJobSchema();
|
|
65
|
+
await client.query(`SELECT * FROM "${schema}".jobs LIMIT 1;`);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
// eslint-disable-next-line no-console
|
|
68
|
+
console.log(error);
|
|
69
|
+
throw new Error('jobs server boot failed...');
|
|
70
|
+
} finally {
|
|
71
|
+
if (client) {
|
|
72
|
+
void client.end();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export const bootJobs = async (): Promise<void> => {
|
|
78
|
+
// eslint-disable-next-line no-console
|
|
79
|
+
console.log('attempting to boot jobs');
|
|
80
|
+
await retry(
|
|
81
|
+
async () => {
|
|
82
|
+
await waitForJobsPrereqs();
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
retries: 10,
|
|
86
|
+
factor: 2
|
|
87
|
+
}
|
|
88
|
+
);
|
|
89
|
+
startJobsServices();
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
if (require.main === module) {
|
|
93
|
+
void bootJobs();
|
|
94
|
+
}
|