@orion-js/dogs 3.1.0-alpha.8 → 3.1.0-alpha.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/lib/events.test.js
CHANGED
|
@@ -17,7 +17,7 @@ describe('Event tests', () => {
|
|
|
17
17
|
workersCount: 1,
|
|
18
18
|
pollInterval: 10,
|
|
19
19
|
cooldownPeriod: 10,
|
|
20
|
-
logLevel: '
|
|
20
|
+
logLevel: 'none'
|
|
21
21
|
});
|
|
22
22
|
expect(count).toBe(0);
|
|
23
23
|
await (0, _1.scheduleJob)({
|
|
@@ -56,7 +56,7 @@ describe('Event tests', () => {
|
|
|
56
56
|
workersCount: 1,
|
|
57
57
|
pollInterval: 10,
|
|
58
58
|
cooldownPeriod: 10,
|
|
59
|
-
logLevel: '
|
|
59
|
+
logLevel: 'none'
|
|
60
60
|
});
|
|
61
61
|
expect(passes).toBe(false);
|
|
62
62
|
await (0, _1.scheduleJob)({
|
|
@@ -91,7 +91,7 @@ describe('Event tests', () => {
|
|
|
91
91
|
pollInterval: 10,
|
|
92
92
|
cooldownPeriod: 10,
|
|
93
93
|
lockTime: 10,
|
|
94
|
-
logLevel: '
|
|
94
|
+
logLevel: 'none'
|
|
95
95
|
});
|
|
96
96
|
await (0, _1.scheduleJob)({
|
|
97
97
|
name: jobId,
|
|
@@ -116,7 +116,7 @@ describe('Event tests', () => {
|
|
|
116
116
|
workersCount: 1,
|
|
117
117
|
pollInterval: 10,
|
|
118
118
|
cooldownPeriod: 10,
|
|
119
|
-
logLevel: '
|
|
119
|
+
logLevel: 'none'
|
|
120
120
|
});
|
|
121
121
|
await (0, _1.scheduleJob)({
|
|
122
122
|
name: jobId,
|
package/lib/recurrent.test.js
CHANGED
|
@@ -18,7 +18,7 @@ describe('Recurrent tests', () => {
|
|
|
18
18
|
workersCount: 1,
|
|
19
19
|
pollInterval: 100,
|
|
20
20
|
cooldownPeriod: 100,
|
|
21
|
-
logLevel: '
|
|
21
|
+
logLevel: 'none'
|
|
22
22
|
});
|
|
23
23
|
await (0, helpers_1.sleep)(500);
|
|
24
24
|
await instance.stop();
|
|
@@ -38,7 +38,7 @@ describe('Recurrent tests', () => {
|
|
|
38
38
|
workersCount: 1,
|
|
39
39
|
pollInterval: 10,
|
|
40
40
|
cooldownPeriod: 10,
|
|
41
|
-
logLevel: '
|
|
41
|
+
logLevel: 'none'
|
|
42
42
|
});
|
|
43
43
|
await (0, helpers_1.sleep)(200);
|
|
44
44
|
await instance.stop();
|
package/lib/repos/JobsRepo.js
CHANGED
|
@@ -67,7 +67,7 @@ let JobsRepo = class JobsRepo {
|
|
|
67
67
|
return;
|
|
68
68
|
let tries = job.tries || 1;
|
|
69
69
|
if (job.lockedUntil) {
|
|
70
|
-
(0, log_1.log)('
|
|
70
|
+
(0, log_1.log)('info', `Running job "${job.jobName}" that was staled`);
|
|
71
71
|
this.jobs.updateOne(job._id, { $inc: { tries: 1 } });
|
|
72
72
|
tries++;
|
|
73
73
|
}
|
|
@@ -116,10 +116,10 @@ let JobsRepo = class JobsRepo {
|
|
|
116
116
|
}
|
|
117
117
|
});
|
|
118
118
|
if (result.upsertedId) {
|
|
119
|
-
(0, log_1.log)('
|
|
119
|
+
(0, log_1.log)('info', `Created job record for "${job.name}"`);
|
|
120
120
|
}
|
|
121
121
|
else {
|
|
122
|
-
(0, log_1.log)('
|
|
122
|
+
(0, log_1.log)('info', `Record for job "${job.name}" already exists`);
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
async scheduleJob(options) {
|
|
@@ -16,7 +16,7 @@ const JobsRepo_1 = require("../repos/JobsRepo");
|
|
|
16
16
|
const getNextRunDate_1 = require("./getNextRunDate");
|
|
17
17
|
let EventsService = class EventsService {
|
|
18
18
|
async scheduleJob(options) {
|
|
19
|
-
(0, log_1.log)('
|
|
19
|
+
(0, log_1.log)('info', 'Scheduling job...', options);
|
|
20
20
|
await this.jobsRepo.scheduleJob({
|
|
21
21
|
name: options.name,
|
|
22
22
|
priority: options.priority || 1,
|
package/lib/services/Executor.js
CHANGED
|
@@ -54,7 +54,7 @@ let Executor = class Executor {
|
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
else {
|
|
57
|
-
(0, log_1.log)('
|
|
57
|
+
(0, log_1.log)('info', `Error executing job "${jobToRun.name}"`, error);
|
|
58
58
|
}
|
|
59
59
|
const result = await job.onError(error, jobToRun.params, context);
|
|
60
60
|
if (result.action === 'dismiss') {
|
|
@@ -94,7 +94,7 @@ let Executor = class Executor {
|
|
|
94
94
|
}
|
|
95
95
|
async afterExecutionSuccess(job, jobToRun) {
|
|
96
96
|
if (job.type === 'recurrent') {
|
|
97
|
-
(0, log_1.log)('
|
|
97
|
+
(0, log_1.log)('info', `Scheduling next run for recurrent job "${jobToRun.name}"`);
|
|
98
98
|
await this.jobsRepo.scheduleNextRun({
|
|
99
99
|
jobId: jobToRun.jobId,
|
|
100
100
|
nextRunAt: (0, getNextRunDate_1.getNextRunDate)(job),
|
|
@@ -102,7 +102,7 @@ let Executor = class Executor {
|
|
|
102
102
|
});
|
|
103
103
|
}
|
|
104
104
|
if (job.type === 'event') {
|
|
105
|
-
(0, log_1.log)('
|
|
105
|
+
(0, log_1.log)('info', `Removing event job after success "${jobToRun.name}"`);
|
|
106
106
|
await this.jobsRepo.deleteEventJob(jobToRun.jobId);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -113,11 +113,11 @@ let Executor = class Executor {
|
|
|
113
113
|
const startedAt = new Date();
|
|
114
114
|
const onStale = () => {
|
|
115
115
|
if (job.onStale) {
|
|
116
|
-
(0, log_1.log)('
|
|
116
|
+
(0, log_1.log)('info', `Job "${jobToRun.name}" is stale`);
|
|
117
117
|
job.onStale(jobToRun.params, context);
|
|
118
118
|
}
|
|
119
119
|
else {
|
|
120
|
-
(0, log_1.log)('
|
|
120
|
+
(0, log_1.log)('error', `Job "${jobToRun.name}" is stale`);
|
|
121
121
|
}
|
|
122
122
|
this.saveExecution({
|
|
123
123
|
startedAt,
|
|
@@ -36,14 +36,14 @@ let WorkerService = class WorkerService {
|
|
|
36
36
|
(0, log_1.log)('debug', 'No job to run');
|
|
37
37
|
return false;
|
|
38
38
|
}
|
|
39
|
-
(0, log_1.log)('
|
|
39
|
+
(0, log_1.log)('info', `Got job to run: ${JSON.stringify(jobToRun)}`);
|
|
40
40
|
await this.executor.executeJob(config.jobs, jobToRun);
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
43
|
async startWorker(config, workersInstance) {
|
|
44
44
|
while (true) {
|
|
45
45
|
if (!workersInstance.running) {
|
|
46
|
-
(0, log_1.log)('
|
|
46
|
+
(0, log_1.log)('info', 'Got signal to stop. Stopping worker...');
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
try {
|
|
@@ -77,15 +77,15 @@ let WorkerService = class WorkerService {
|
|
|
77
77
|
await Promise.all(jobs
|
|
78
78
|
.filter(job => job.type === 'recurrent')
|
|
79
79
|
.map(async (job) => {
|
|
80
|
-
(0, log_1.log)('
|
|
80
|
+
(0, log_1.log)('info', `Ensuring records for job "${job.name}"...`);
|
|
81
81
|
await this.jobsRepo.ensureJobRecord(job);
|
|
82
82
|
}));
|
|
83
83
|
}
|
|
84
84
|
async runWorkers(config, workersInstance) {
|
|
85
|
-
(0, log_1.log)('
|
|
85
|
+
(0, log_1.log)('info', 'Will ensure records for recurrent jobs');
|
|
86
86
|
await this.ensureRecords(config);
|
|
87
87
|
for (const workerIndex of (0, lodash_1.range)(config.workersCount)) {
|
|
88
|
-
(0, log_1.log)('
|
|
88
|
+
(0, log_1.log)('info', `Starting worker ${workerIndex}`);
|
|
89
89
|
const workerPromise = this.startWorker(config, workersInstance);
|
|
90
90
|
workersInstance.workers.push(workerPromise);
|
|
91
91
|
}
|
|
@@ -105,7 +105,7 @@ let WorkerService = class WorkerService {
|
|
|
105
105
|
};
|
|
106
106
|
(0, log_1.setLogLevel)(config.logLevel);
|
|
107
107
|
const workersInstance = this.createWorkersInstanceDefinition(config);
|
|
108
|
-
(0, log_1.log)('
|
|
108
|
+
(0, log_1.log)('info', 'Starting workers', config);
|
|
109
109
|
this.runWorkers(config, workersInstance);
|
|
110
110
|
return workersInstance;
|
|
111
111
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/dogs",
|
|
3
|
-
"version": "3.1.0-alpha.
|
|
3
|
+
"version": "3.1.0-alpha.9",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "65ebf7047a46aa5e93e9066d82ca70f81d69f10c"
|
|
39
39
|
}
|