@orion-js/dogs 3.2.1 → 3.2.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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ModelToDocumentTypeWithoutId } from '@orion-js/mongodb';
|
|
2
2
|
import { HistoryRecord } from '../types/HistoryRecord';
|
|
3
3
|
export declare class JobsHistoryRepo {
|
|
4
|
-
history: import("@orion-js/mongodb").Collection<HistoryRecord>;
|
|
4
|
+
history: () => import("@orion-js/mongodb").Collection<HistoryRecord>;
|
|
5
5
|
saveExecution(record: ModelToDocumentTypeWithoutId<HistoryRecord>): Promise<void>;
|
|
6
6
|
getExecutions(jobName: string, limit?: number, skip?: number): Promise<HistoryRecord[]>;
|
|
7
7
|
}
|
|
@@ -13,7 +13,7 @@ const lodash_1 = require("lodash");
|
|
|
13
13
|
const HistoryRecord_1 = require("../types/HistoryRecord");
|
|
14
14
|
let JobsHistoryRepo = class JobsHistoryRepo {
|
|
15
15
|
constructor() {
|
|
16
|
-
this.history = (0, mongodb_1.createCollection)({
|
|
16
|
+
this.history = () => (0, mongodb_1.createCollection)({
|
|
17
17
|
name: 'orionjs.jobs_dogs_history',
|
|
18
18
|
model: HistoryRecord_1.HistoryRecord,
|
|
19
19
|
indexes: [
|
|
@@ -35,7 +35,7 @@ let JobsHistoryRepo = class JobsHistoryRepo {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
async saveExecution(record) {
|
|
38
|
-
await this.history.upsert({ executionId: record.executionId }, {
|
|
38
|
+
await this.history().upsert({ executionId: record.executionId }, {
|
|
39
39
|
$setOnInsert: {
|
|
40
40
|
status: record.status
|
|
41
41
|
},
|
|
@@ -45,7 +45,7 @@ let JobsHistoryRepo = class JobsHistoryRepo {
|
|
|
45
45
|
});
|
|
46
46
|
}
|
|
47
47
|
async getExecutions(jobName, limit, skip) {
|
|
48
|
-
const cursor = this.history.find({ jobName }).sort({ startedAt: -1 });
|
|
48
|
+
const cursor = this.history().find({ jobName }).sort({ startedAt: -1 });
|
|
49
49
|
if (skip) {
|
|
50
50
|
cursor.skip(skip);
|
|
51
51
|
}
|
package/lib/repos/JobsRepo.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { JobRecord } from '../types/JobRecord';
|
|
|
3
3
|
import { JobDefinitionWithName } from '../types/JobsDefinition';
|
|
4
4
|
import { JobToRun } from '../types/Worker';
|
|
5
5
|
export declare class JobsRepo {
|
|
6
|
-
jobs: import("@orion-js/mongodb").Collection<JobRecord>;
|
|
6
|
+
jobs: () => import("@orion-js/mongodb").Collection<JobRecord>;
|
|
7
7
|
getJobAndLock(jobNames: string[], lockTime: number): Promise<JobToRun>;
|
|
8
8
|
setJobRecordPriority(jobId: string, priority: number): Promise<void>;
|
|
9
9
|
scheduleNextRun(options: {
|
package/lib/repos/JobsRepo.js
CHANGED
|
@@ -15,7 +15,7 @@ const lodash_1 = require("lodash");
|
|
|
15
15
|
const JobRecord_1 = require("../types/JobRecord");
|
|
16
16
|
let JobsRepo = class JobsRepo {
|
|
17
17
|
constructor() {
|
|
18
|
-
this.jobs = (0, mongodb_1.createCollection)({
|
|
18
|
+
this.jobs = () => (0, mongodb_1.createCollection)({
|
|
19
19
|
name: 'orionjs.jobs_dogs_records',
|
|
20
20
|
model: JobRecord_1.JobRecord,
|
|
21
21
|
indexes: [
|
|
@@ -50,7 +50,7 @@ let JobsRepo = class JobsRepo {
|
|
|
50
50
|
}
|
|
51
51
|
async getJobAndLock(jobNames, lockTime) {
|
|
52
52
|
const lockedUntil = new Date(Date.now() + lockTime);
|
|
53
|
-
const job = await this.jobs.findOneAndUpdate({
|
|
53
|
+
const job = await this.jobs().findOneAndUpdate({
|
|
54
54
|
jobName: { $in: jobNames },
|
|
55
55
|
nextRunAt: { $lte: new Date() },
|
|
56
56
|
$or: [{ lockedUntil: { $exists: false } }, { lockedUntil: { $lte: new Date() } }]
|
|
@@ -70,7 +70,7 @@ let JobsRepo = class JobsRepo {
|
|
|
70
70
|
let tries = job.tries || 1;
|
|
71
71
|
if (job.lockedUntil) {
|
|
72
72
|
logger_1.logger.info(`Running job "${job.jobName}" that was staled`);
|
|
73
|
-
this.jobs.updateOne(job._id, { $inc: { tries: 1 } });
|
|
73
|
+
this.jobs().updateOne(job._id, { $inc: { tries: 1 } });
|
|
74
74
|
tries++;
|
|
75
75
|
}
|
|
76
76
|
return {
|
|
@@ -86,7 +86,7 @@ let JobsRepo = class JobsRepo {
|
|
|
86
86
|
};
|
|
87
87
|
}
|
|
88
88
|
async setJobRecordPriority(jobId, priority) {
|
|
89
|
-
await this.jobs.updateOne(jobId, { $set: { priority } });
|
|
89
|
+
await this.jobs().updateOne(jobId, { $set: { priority } });
|
|
90
90
|
}
|
|
91
91
|
async scheduleNextRun(options) {
|
|
92
92
|
const updator = {
|
|
@@ -96,22 +96,22 @@ let JobsRepo = class JobsRepo {
|
|
|
96
96
|
if (options.addTries) {
|
|
97
97
|
updator.$inc = { tries: 1 };
|
|
98
98
|
}
|
|
99
|
-
await this.jobs.updateOne(options.jobId, updator);
|
|
99
|
+
await this.jobs().updateOne(options.jobId, updator);
|
|
100
100
|
}
|
|
101
101
|
async deleteEventJob(jobId) {
|
|
102
|
-
await this.jobs.deleteOne({ _id: jobId, type: 'event' });
|
|
102
|
+
await this.jobs().deleteOne({ _id: jobId, type: 'event' });
|
|
103
103
|
}
|
|
104
104
|
async extendLockTime(jobId, extraTime) {
|
|
105
105
|
const lockedUntil = new Date(Date.now() + extraTime);
|
|
106
|
-
await this.jobs.updateOne({
|
|
106
|
+
await this.jobs().updateOne({
|
|
107
107
|
_id: jobId
|
|
108
108
|
}, {
|
|
109
109
|
$set: { lockedUntil }
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
112
|
async ensureJobRecord(job) {
|
|
113
|
-
await this.jobs.connectionPromise;
|
|
114
|
-
const result = await this.jobs.upsert({
|
|
113
|
+
await this.jobs().connectionPromise;
|
|
114
|
+
const result = await this.jobs().upsert({
|
|
115
115
|
jobName: job.name
|
|
116
116
|
}, {
|
|
117
117
|
$set: {
|
|
@@ -131,7 +131,7 @@ let JobsRepo = class JobsRepo {
|
|
|
131
131
|
}
|
|
132
132
|
async scheduleJob(options) {
|
|
133
133
|
try {
|
|
134
|
-
await this.jobs.insertOne({
|
|
134
|
+
await this.jobs().insertOne({
|
|
135
135
|
jobName: options.name,
|
|
136
136
|
uniqueIdentifier: options.uniqueIdentifier,
|
|
137
137
|
params: options.params,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orion-js/dogs",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"files": [
|
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"@orion-js/helpers": "^3.2.0",
|
|
21
|
-
"@orion-js/mongodb": "^3.2.
|
|
21
|
+
"@orion-js/mongodb": "^3.2.2",
|
|
22
22
|
"@orion-js/services": "^3.2.0",
|
|
23
|
-
"@orion-js/typed-model": "^3.2.
|
|
23
|
+
"@orion-js/typed-model": "^3.2.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"@orion-js/logger": "3.1.0-alpha.12"
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "95d6f776514b789bb1c267ee9fbe3b4eaa4c961d"
|
|
43
43
|
}
|