@orion-js/dogs 3.11.15 → 4.0.0-alpha.3
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/index.cjs +114048 -0
- package/dist/index.d.ts +748 -0
- package/dist/index.js +114022 -0
- package/package.json +23 -22
- package/LICENSE +0 -21
- package/lib/defineJob/index.d.ts +0 -2
- package/lib/defineJob/index.js +0 -12
- package/lib/events.test.d.ts +0 -1
- package/lib/events.test.js +0 -133
- package/lib/history.test.d.ts +0 -1
- package/lib/history.test.js +0 -140
- package/lib/index.d.ts +0 -12
- package/lib/index.js +0 -40
- package/lib/recurrent.test.d.ts +0 -1
- package/lib/recurrent.test.js +0 -47
- package/lib/repos/JobsHistoryRepo.d.ts +0 -7
- package/lib/repos/JobsHistoryRepo.js +0 -67
- package/lib/repos/JobsRepo.d.ts +0 -19
- package/lib/repos/JobsRepo.js +0 -158
- package/lib/service/index.d.ts +0 -10
- package/lib/service/index.js +0 -50
- package/lib/service/index.test.d.ts +0 -1
- package/lib/service/index.test.js +0 -51
- package/lib/services/EventsService.d.ts +0 -5
- package/lib/services/EventsService.js +0 -36
- package/lib/services/Executor.d.ts +0 -20
- package/lib/services/Executor.js +0 -195
- package/lib/services/WorkerService.d.ts +0 -16
- package/lib/services/WorkerService.js +0 -142
- package/lib/services/WorkerService.test.d.ts +0 -1
- package/lib/services/WorkerService.test.js +0 -10
- package/lib/services/getNextRunDate.d.ts +0 -9
- package/lib/services/getNextRunDate.js +0 -19
- package/lib/stale.test.d.ts +0 -1
- package/lib/stale.test.js +0 -108
- package/lib/tests/setup.d.ts +0 -1
- package/lib/tests/setup.js +0 -19
- package/lib/types/Events.d.ts +0 -21
- package/lib/types/Events.js +0 -2
- package/lib/types/HistoryRecord.d.ts +0 -21
- package/lib/types/HistoryRecord.js +0 -83
- package/lib/types/JobRecord.d.ts +0 -13
- package/lib/types/JobRecord.js +0 -59
- package/lib/types/JobsDefinition.d.ts +0 -61
- package/lib/types/JobsDefinition.js +0 -2
- package/lib/types/StartConfig.d.ts +0 -28
- package/lib/types/StartConfig.js +0 -2
- package/lib/types/Worker.d.ts +0 -38
- package/lib/types/Worker.js +0 -2
- package/lib/types/index.d.ts +0 -6
- package/lib/types/index.js +0 -22
package/package.json
CHANGED
|
@@ -1,44 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/dogs",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "4.0.0-alpha.3",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
6
13
|
"files": [
|
|
7
|
-
"
|
|
14
|
+
"dist"
|
|
8
15
|
],
|
|
9
16
|
"author": "nicolaslopezj",
|
|
10
17
|
"license": "MIT",
|
|
11
18
|
"scripts": {
|
|
12
|
-
"test": "
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"watch": "tsc -w",
|
|
17
|
-
"upgrade-interactive": "yarn upgrade-interactive"
|
|
19
|
+
"test": "bun test",
|
|
20
|
+
"build": "bun run build.ts",
|
|
21
|
+
"dev": "bun --watch src/index.ts",
|
|
22
|
+
"clean": "rm -rf ./dist"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
25
|
"@opentelemetry/api": "^1.9.0",
|
|
21
|
-
"@orion-js/helpers": "^
|
|
22
|
-
"@orion-js/mongodb": "^
|
|
23
|
-
"@orion-js/services": "^
|
|
24
|
-
"@orion-js/typed-model": "^
|
|
26
|
+
"@orion-js/helpers": "^4.0.0-alpha.2",
|
|
27
|
+
"@orion-js/mongodb": "^4.0.0-alpha.2",
|
|
28
|
+
"@orion-js/services": "^4.0.0-alpha.2",
|
|
29
|
+
"@orion-js/typed-model": "^4.0.0-alpha.2"
|
|
25
30
|
},
|
|
26
31
|
"peerDependencies": {
|
|
27
32
|
"@orion-js/logger": "*"
|
|
28
33
|
},
|
|
29
34
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@types/jest": "^29.5.12",
|
|
35
|
+
"@types/bun": "^1.2.4",
|
|
36
|
+
"@orion-js/logger": "^4.0.0-alpha.2",
|
|
33
37
|
"@types/lodash": "4.14.176",
|
|
34
|
-
"@types/node": "16.11.7",
|
|
35
|
-
"jest": "29.7.0",
|
|
36
38
|
"reflect-metadata": "^0.1.13",
|
|
37
|
-
"ts-jest": "29.1.2",
|
|
38
39
|
"typescript": "^5.4.5"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
-
}
|
|
44
|
+
"gitHead": "2d14bc085d49a33b2a5566bec1caf60c7d0f897e"
|
|
45
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2022 Orionjs Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/lib/defineJob/index.d.ts
DELETED
package/lib/defineJob/index.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defineJob = void 0;
|
|
4
|
-
const defineJob = (options) => {
|
|
5
|
-
if (options.type === 'recurrent') {
|
|
6
|
-
if (!options.hasOwnProperty('priority')) {
|
|
7
|
-
options.priority = 100;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return options;
|
|
11
|
-
};
|
|
12
|
-
exports.defineJob = defineJob;
|
package/lib/events.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
package/lib/events.test.js
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
require("reflect-metadata");
|
|
4
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
5
|
-
const _1 = require(".");
|
|
6
|
-
const logger_1 = require("@orion-js/logger");
|
|
7
|
-
(0, logger_1.setLogLevel)('error');
|
|
8
|
-
describe('Event tests', () => {
|
|
9
|
-
it('Should run an event job', async () => {
|
|
10
|
-
let count = 0;
|
|
11
|
-
const job3 = (0, _1.defineJob)({
|
|
12
|
-
type: 'event',
|
|
13
|
-
async resolve(params) {
|
|
14
|
-
count += params.add;
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
const instance = (0, _1.startWorkers)({
|
|
18
|
-
jobs: { job3 },
|
|
19
|
-
workersCount: 1,
|
|
20
|
-
pollInterval: 10,
|
|
21
|
-
cooldownPeriod: 10
|
|
22
|
-
});
|
|
23
|
-
expect(count).toBe(0);
|
|
24
|
-
await (0, _1.scheduleJob)({
|
|
25
|
-
name: 'job3',
|
|
26
|
-
params: { add: 5 },
|
|
27
|
-
runIn: 1
|
|
28
|
-
});
|
|
29
|
-
await (0, _1.scheduleJob)({
|
|
30
|
-
name: 'job3',
|
|
31
|
-
params: { add: 25 },
|
|
32
|
-
runIn: 1
|
|
33
|
-
});
|
|
34
|
-
await (0, helpers_1.sleep)(100);
|
|
35
|
-
await instance.stop();
|
|
36
|
-
expect(count).toBe(30);
|
|
37
|
-
});
|
|
38
|
-
it('Should run retry the job 3 times', async () => {
|
|
39
|
-
let passes = false;
|
|
40
|
-
const job4 = (0, _1.defineJob)({
|
|
41
|
-
type: 'event',
|
|
42
|
-
async resolve(params, context) {
|
|
43
|
-
if (context.tries < 3) {
|
|
44
|
-
throw new Error('Failed');
|
|
45
|
-
}
|
|
46
|
-
passes = true;
|
|
47
|
-
},
|
|
48
|
-
async onError() {
|
|
49
|
-
return {
|
|
50
|
-
action: 'retry',
|
|
51
|
-
runIn: 1
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
const instance = (0, _1.startWorkers)({
|
|
56
|
-
jobs: { job4 },
|
|
57
|
-
workersCount: 1,
|
|
58
|
-
pollInterval: 10,
|
|
59
|
-
cooldownPeriod: 10
|
|
60
|
-
});
|
|
61
|
-
expect(passes).toBe(false);
|
|
62
|
-
await (0, _1.scheduleJob)({
|
|
63
|
-
name: 'job4',
|
|
64
|
-
runIn: 1
|
|
65
|
-
});
|
|
66
|
-
await (0, helpers_1.sleep)(100);
|
|
67
|
-
await instance.stop();
|
|
68
|
-
expect(passes).toBe(true);
|
|
69
|
-
});
|
|
70
|
-
it('Should throw locktime error and test extendLockTime', async () => {
|
|
71
|
-
const jobId = (0, helpers_1.generateId)();
|
|
72
|
-
let ranCount = 0;
|
|
73
|
-
let staleCount = 0;
|
|
74
|
-
const job = (0, _1.defineJob)({
|
|
75
|
-
type: 'event',
|
|
76
|
-
async resolve(params, context) {
|
|
77
|
-
if (context.tries === 2) {
|
|
78
|
-
context.extendLockTime(10000);
|
|
79
|
-
}
|
|
80
|
-
await (0, helpers_1.sleep)(100);
|
|
81
|
-
ranCount++;
|
|
82
|
-
},
|
|
83
|
-
async onStale(params, context) {
|
|
84
|
-
expect(context.tries).toBe(1);
|
|
85
|
-
staleCount++;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
const instance = (0, _1.startWorkers)({
|
|
89
|
-
jobs: { [jobId]: job },
|
|
90
|
-
workersCount: 2,
|
|
91
|
-
pollInterval: 10,
|
|
92
|
-
cooldownPeriod: 10,
|
|
93
|
-
lockTime: 10
|
|
94
|
-
});
|
|
95
|
-
await (0, _1.scheduleJob)({
|
|
96
|
-
name: jobId,
|
|
97
|
-
runIn: 1
|
|
98
|
-
});
|
|
99
|
-
await (0, helpers_1.sleep)(300);
|
|
100
|
-
await instance.stop();
|
|
101
|
-
expect(staleCount).toBe(1);
|
|
102
|
-
expect(ranCount).toBe(2);
|
|
103
|
-
});
|
|
104
|
-
it('Should only schedule one job with uniqueIdentifier', async () => {
|
|
105
|
-
const jobId = (0, helpers_1.generateId)();
|
|
106
|
-
let ranCount = 0;
|
|
107
|
-
const job = (0, _1.defineJob)({
|
|
108
|
-
type: 'event',
|
|
109
|
-
async resolve() {
|
|
110
|
-
ranCount++;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
const instance = (0, _1.startWorkers)({
|
|
114
|
-
jobs: { [jobId]: job },
|
|
115
|
-
workersCount: 1,
|
|
116
|
-
pollInterval: 10,
|
|
117
|
-
cooldownPeriod: 10
|
|
118
|
-
});
|
|
119
|
-
await (0, _1.scheduleJob)({
|
|
120
|
-
name: jobId,
|
|
121
|
-
runIn: 1,
|
|
122
|
-
uniqueIdentifier: 'unique'
|
|
123
|
-
});
|
|
124
|
-
await (0, _1.scheduleJob)({
|
|
125
|
-
name: jobId,
|
|
126
|
-
runIn: 1,
|
|
127
|
-
uniqueIdentifier: 'unique'
|
|
128
|
-
});
|
|
129
|
-
await (0, helpers_1.sleep)(50);
|
|
130
|
-
await instance.stop();
|
|
131
|
-
expect(ranCount).toBe(1);
|
|
132
|
-
});
|
|
133
|
-
});
|
package/lib/history.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/history.test.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
4
|
-
const _1 = require(".");
|
|
5
|
-
const logger_1 = require("@orion-js/logger");
|
|
6
|
-
(0, logger_1.setLogLevel)('none');
|
|
7
|
-
describe('Test Jobs History', () => {
|
|
8
|
-
it('Should save success history types', async () => {
|
|
9
|
-
const jobId = (0, helpers_1.generateId)();
|
|
10
|
-
const job = (0, _1.defineJob)({
|
|
11
|
-
type: 'event',
|
|
12
|
-
async resolve() {
|
|
13
|
-
await (0, helpers_1.sleep)(50);
|
|
14
|
-
return {
|
|
15
|
-
number: 1
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
const instance = (0, _1.startWorkers)({
|
|
20
|
-
jobs: { [jobId]: job },
|
|
21
|
-
workersCount: 1,
|
|
22
|
-
pollInterval: 10
|
|
23
|
-
});
|
|
24
|
-
await (0, _1.scheduleJob)({
|
|
25
|
-
name: jobId,
|
|
26
|
-
runIn: 1,
|
|
27
|
-
params: { id: 2 }
|
|
28
|
-
});
|
|
29
|
-
await (0, helpers_1.sleep)(100);
|
|
30
|
-
await instance.stop();
|
|
31
|
-
const executions = await _1.jobsHistoryRepo.getExecutions(jobId);
|
|
32
|
-
expect(executions.length).toBe(1);
|
|
33
|
-
const execution = executions[0];
|
|
34
|
-
expect(execution.duration).toBeGreaterThan(49);
|
|
35
|
-
expect(execution).toEqual({
|
|
36
|
-
_id: expect.any(String),
|
|
37
|
-
jobId: expect.any(String),
|
|
38
|
-
executionId: expect.any(String),
|
|
39
|
-
jobName: jobId,
|
|
40
|
-
type: 'event',
|
|
41
|
-
priority: 100,
|
|
42
|
-
tries: 1,
|
|
43
|
-
startedAt: expect.any(Date),
|
|
44
|
-
endedAt: expect.any(Date),
|
|
45
|
-
duration: expect.any(Number),
|
|
46
|
-
expiresAt: expect.any(Date),
|
|
47
|
-
status: 'success',
|
|
48
|
-
errorMessage: null,
|
|
49
|
-
params: { id: 2 },
|
|
50
|
-
result: { number: 1 }
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
it('Should save error history types', async () => {
|
|
54
|
-
const jobId = (0, helpers_1.generateId)();
|
|
55
|
-
const job = (0, _1.defineJob)({
|
|
56
|
-
type: 'event',
|
|
57
|
-
async resolve() {
|
|
58
|
-
throw new Error('Hello');
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
const instance = (0, _1.startWorkers)({
|
|
62
|
-
jobs: { [jobId]: job },
|
|
63
|
-
workersCount: 1,
|
|
64
|
-
pollInterval: 10
|
|
65
|
-
});
|
|
66
|
-
await (0, _1.scheduleJob)({
|
|
67
|
-
name: jobId,
|
|
68
|
-
runIn: 1,
|
|
69
|
-
params: { id: 4 }
|
|
70
|
-
});
|
|
71
|
-
await (0, helpers_1.sleep)(100);
|
|
72
|
-
await instance.stop();
|
|
73
|
-
const executions = await _1.jobsHistoryRepo.getExecutions(jobId);
|
|
74
|
-
expect(executions.length).toBe(1);
|
|
75
|
-
const execution = executions[0];
|
|
76
|
-
expect(execution).toEqual({
|
|
77
|
-
_id: expect.any(String),
|
|
78
|
-
jobId: expect.any(String),
|
|
79
|
-
executionId: expect.any(String),
|
|
80
|
-
jobName: jobId,
|
|
81
|
-
type: 'event',
|
|
82
|
-
priority: 100,
|
|
83
|
-
tries: 1,
|
|
84
|
-
startedAt: expect.any(Date),
|
|
85
|
-
endedAt: expect.any(Date),
|
|
86
|
-
duration: expect.any(Number),
|
|
87
|
-
expiresAt: expect.any(Date),
|
|
88
|
-
status: 'error',
|
|
89
|
-
errorMessage: 'Hello',
|
|
90
|
-
params: { id: 4 },
|
|
91
|
-
result: null
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
it('Should save stale history types', async () => {
|
|
95
|
-
const jobId = (0, helpers_1.generateId)();
|
|
96
|
-
const job = (0, _1.defineJob)({
|
|
97
|
-
type: 'event',
|
|
98
|
-
async resolve(_, context) {
|
|
99
|
-
if (context.tries === 1) {
|
|
100
|
-
await (0, helpers_1.sleep)(100);
|
|
101
|
-
}
|
|
102
|
-
return { status: 'ok' };
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
const instance = (0, _1.startWorkers)({
|
|
106
|
-
jobs: { [jobId]: job },
|
|
107
|
-
workersCount: 1,
|
|
108
|
-
pollInterval: 10,
|
|
109
|
-
lockTime: 10
|
|
110
|
-
});
|
|
111
|
-
await (0, _1.scheduleJob)({
|
|
112
|
-
name: jobId,
|
|
113
|
-
runIn: 1
|
|
114
|
-
});
|
|
115
|
-
await (0, helpers_1.sleep)(150);
|
|
116
|
-
await instance.stop();
|
|
117
|
-
const executions = await _1.jobsHistoryRepo.getExecutions(jobId);
|
|
118
|
-
expect(executions.length).toBe(2);
|
|
119
|
-
const execution = executions.find(e => e.status === 'stale');
|
|
120
|
-
expect(execution.duration).toBeGreaterThanOrEqual(100);
|
|
121
|
-
expect(execution.duration).toBeLessThan(200);
|
|
122
|
-
expect(execution).toEqual({
|
|
123
|
-
_id: expect.any(String),
|
|
124
|
-
jobId: expect.any(String),
|
|
125
|
-
executionId: expect.any(String),
|
|
126
|
-
jobName: jobId,
|
|
127
|
-
type: 'event',
|
|
128
|
-
priority: 100,
|
|
129
|
-
tries: 1,
|
|
130
|
-
startedAt: expect.any(Date),
|
|
131
|
-
endedAt: expect.any(Date),
|
|
132
|
-
duration: expect.any(Number),
|
|
133
|
-
expiresAt: expect.any(Date),
|
|
134
|
-
status: 'stale',
|
|
135
|
-
errorMessage: null,
|
|
136
|
-
params: null,
|
|
137
|
-
result: { status: 'ok' }
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
});
|
package/lib/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { defineJob } from './defineJob';
|
|
2
|
-
import { StartWorkersConfig } from './types/StartConfig';
|
|
3
|
-
import { ScheduleJobOptions } from './types/Events';
|
|
4
|
-
import { JobsHistoryRepo } from './repos/JobsHistoryRepo';
|
|
5
|
-
import { JobsRepo } from './repos/JobsRepo';
|
|
6
|
-
export * from './types';
|
|
7
|
-
export * from './service';
|
|
8
|
-
declare const jobsHistoryRepo: JobsHistoryRepo;
|
|
9
|
-
declare const jobsRepo: JobsRepo;
|
|
10
|
-
declare const startWorkers: (config: Partial<StartWorkersConfig>) => import("./types").WorkersInstance;
|
|
11
|
-
declare const scheduleJob: (options: ScheduleJobOptions) => Promise<void>;
|
|
12
|
-
export { defineJob, startWorkers, scheduleJob, jobsHistoryRepo, jobsRepo };
|
package/lib/index.js
DELETED
|
@@ -1,40 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.jobsRepo = exports.jobsHistoryRepo = exports.scheduleJob = exports.startWorkers = exports.defineJob = void 0;
|
|
18
|
-
const services_1 = require("@orion-js/services");
|
|
19
|
-
const defineJob_1 = require("./defineJob");
|
|
20
|
-
Object.defineProperty(exports, "defineJob", { enumerable: true, get: function () { return defineJob_1.defineJob; } });
|
|
21
|
-
const EventsService_1 = require("./services/EventsService");
|
|
22
|
-
const WorkerService_1 = require("./services/WorkerService");
|
|
23
|
-
const JobsHistoryRepo_1 = require("./repos/JobsHistoryRepo");
|
|
24
|
-
const JobsRepo_1 = require("./repos/JobsRepo");
|
|
25
|
-
__exportStar(require("./types"), exports);
|
|
26
|
-
__exportStar(require("./service"), exports);
|
|
27
|
-
const workerService = (0, services_1.getInstance)(WorkerService_1.WorkerService);
|
|
28
|
-
const eventsService = (0, services_1.getInstance)(EventsService_1.EventsService);
|
|
29
|
-
const jobsHistoryRepo = (0, services_1.getInstance)(JobsHistoryRepo_1.JobsHistoryRepo);
|
|
30
|
-
exports.jobsHistoryRepo = jobsHistoryRepo;
|
|
31
|
-
const jobsRepo = (0, services_1.getInstance)(JobsRepo_1.JobsRepo);
|
|
32
|
-
exports.jobsRepo = jobsRepo;
|
|
33
|
-
const startWorkers = (config) => {
|
|
34
|
-
return workerService.startWorkers(config);
|
|
35
|
-
};
|
|
36
|
-
exports.startWorkers = startWorkers;
|
|
37
|
-
const scheduleJob = (options) => {
|
|
38
|
-
return eventsService.scheduleJob(options);
|
|
39
|
-
};
|
|
40
|
-
exports.scheduleJob = scheduleJob;
|
package/lib/recurrent.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
package/lib/recurrent.test.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
require("reflect-metadata");
|
|
4
|
-
const helpers_1 = require("@orion-js/helpers");
|
|
5
|
-
const _1 = require(".");
|
|
6
|
-
const logger_1 = require("@orion-js/logger");
|
|
7
|
-
(0, logger_1.setLogLevel)('error');
|
|
8
|
-
describe('Recurrent tests', () => {
|
|
9
|
-
it('Should run a recurrent job', async () => {
|
|
10
|
-
let ran = false;
|
|
11
|
-
const job1 = (0, _1.defineJob)({
|
|
12
|
-
type: 'recurrent',
|
|
13
|
-
runEvery: 1000,
|
|
14
|
-
async resolve() {
|
|
15
|
-
ran = true;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
const instance = (0, _1.startWorkers)({
|
|
19
|
-
jobs: { job1 },
|
|
20
|
-
workersCount: 1,
|
|
21
|
-
pollInterval: 100,
|
|
22
|
-
cooldownPeriod: 100
|
|
23
|
-
});
|
|
24
|
-
await (0, helpers_1.sleep)(500);
|
|
25
|
-
await instance.stop();
|
|
26
|
-
expect(ran).toBe(true);
|
|
27
|
-
});
|
|
28
|
-
it('Should run a recurrent job 3 times', async () => {
|
|
29
|
-
let count = 0;
|
|
30
|
-
const job2 = (0, _1.defineJob)({
|
|
31
|
-
type: 'recurrent',
|
|
32
|
-
runEvery: 20,
|
|
33
|
-
async resolve() {
|
|
34
|
-
count++;
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
const instance = (0, _1.startWorkers)({
|
|
38
|
-
jobs: { job2 },
|
|
39
|
-
workersCount: 1,
|
|
40
|
-
pollInterval: 10,
|
|
41
|
-
cooldownPeriod: 10
|
|
42
|
-
});
|
|
43
|
-
await (0, helpers_1.sleep)(200);
|
|
44
|
-
await instance.stop();
|
|
45
|
-
expect(count).toBeGreaterThanOrEqual(3);
|
|
46
|
-
});
|
|
47
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { ModelToDocumentTypeWithoutId } from '@orion-js/mongodb';
|
|
2
|
-
import { HistoryRecord } from '../types/HistoryRecord';
|
|
3
|
-
export declare class JobsHistoryRepo {
|
|
4
|
-
history: () => import("@orion-js/mongodb").Collection<HistoryRecord>;
|
|
5
|
-
saveExecution(record: ModelToDocumentTypeWithoutId<HistoryRecord>): Promise<void>;
|
|
6
|
-
getExecutions(jobName: string, limit?: number, skip?: number): Promise<HistoryRecord[]>;
|
|
7
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.JobsHistoryRepo = void 0;
|
|
10
|
-
const mongodb_1 = require("@orion-js/mongodb");
|
|
11
|
-
const services_1 = require("@orion-js/services");
|
|
12
|
-
const lodash_1 = require("lodash");
|
|
13
|
-
const HistoryRecord_1 = require("../types/HistoryRecord");
|
|
14
|
-
let JobsHistoryRepo = class JobsHistoryRepo {
|
|
15
|
-
constructor() {
|
|
16
|
-
this.history = () => (0, mongodb_1.createCollection)({
|
|
17
|
-
name: 'orionjs.jobs_dogs_history',
|
|
18
|
-
idGeneration: 'uuid',
|
|
19
|
-
model: HistoryRecord_1.HistoryRecord,
|
|
20
|
-
indexes: [
|
|
21
|
-
{
|
|
22
|
-
keys: {
|
|
23
|
-
jobName: 1,
|
|
24
|
-
startedAt: 1
|
|
25
|
-
}
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
keys: {
|
|
29
|
-
executionId: 1
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
{
|
|
33
|
-
keys: {
|
|
34
|
-
expiresAt: 1
|
|
35
|
-
},
|
|
36
|
-
options: {
|
|
37
|
-
expireAfterSeconds: 0
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async saveExecution(record) {
|
|
44
|
-
await this.history().upsert({ executionId: record.executionId }, {
|
|
45
|
-
$setOnInsert: {
|
|
46
|
-
status: record.status
|
|
47
|
-
},
|
|
48
|
-
$set: {
|
|
49
|
-
...(0, lodash_1.omit)(record, 'status')
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
async getExecutions(jobName, limit, skip) {
|
|
54
|
-
const cursor = this.history().find({ jobName }).sort({ startedAt: -1 });
|
|
55
|
-
if (skip) {
|
|
56
|
-
cursor.skip(skip);
|
|
57
|
-
}
|
|
58
|
-
if (limit) {
|
|
59
|
-
cursor.limit(limit);
|
|
60
|
-
}
|
|
61
|
-
return await cursor.toArray();
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
exports.JobsHistoryRepo = JobsHistoryRepo;
|
|
65
|
-
exports.JobsHistoryRepo = JobsHistoryRepo = __decorate([
|
|
66
|
-
(0, services_1.Service)()
|
|
67
|
-
], JobsHistoryRepo);
|
package/lib/repos/JobsRepo.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ScheduleJobRecordOptions } from '../types/Events';
|
|
2
|
-
import { JobRecord } from '../types/JobRecord';
|
|
3
|
-
import { JobDefinitionWithName } from '../types/JobsDefinition';
|
|
4
|
-
import { JobToRun } from '../types/Worker';
|
|
5
|
-
export declare class JobsRepo {
|
|
6
|
-
jobs: () => import("@orion-js/mongodb").Collection<JobRecord>;
|
|
7
|
-
getJobAndLock(jobNames: string[], lockTime: number): Promise<JobToRun>;
|
|
8
|
-
setJobRecordPriority(jobId: string, priority: number): Promise<void>;
|
|
9
|
-
scheduleNextRun(options: {
|
|
10
|
-
jobId: string;
|
|
11
|
-
nextRunAt: Date;
|
|
12
|
-
addTries: boolean;
|
|
13
|
-
priority: number;
|
|
14
|
-
}): Promise<void>;
|
|
15
|
-
deleteEventJob(jobId: string): Promise<void>;
|
|
16
|
-
extendLockTime(jobId: string, extraTime: number): Promise<void>;
|
|
17
|
-
ensureJobRecord(job: JobDefinitionWithName): Promise<void>;
|
|
18
|
-
scheduleJob(options: ScheduleJobRecordOptions): Promise<void>;
|
|
19
|
-
}
|