@chevre/domain 21.30.0-alpha.7 → 21.30.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.
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// tslint:disable:no-implicit-dependencies no-console
|
|
2
|
+
import { chevre } from '../../../lib/index';
|
|
3
|
+
|
|
4
|
+
import * as mongoose from 'mongoose';
|
|
5
|
+
|
|
6
|
+
// const project = { id: String(process.env.PROJECT_ID) };
|
|
7
|
+
|
|
8
|
+
mongoose.Model.on('index', (...args) => {
|
|
9
|
+
console.error('******** index event emitted. ********\n', args);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
async function main() {
|
|
13
|
+
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
|
|
14
|
+
|
|
15
|
+
const indexes = await mongoose.connection.db.collection('tasks')
|
|
16
|
+
.indexes();
|
|
17
|
+
// console.log(indexes);
|
|
18
|
+
console.log(indexes.length, 'indexes found');
|
|
19
|
+
|
|
20
|
+
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
21
|
+
const tasks = await taskRepo.search(
|
|
22
|
+
{
|
|
23
|
+
limit: 1,
|
|
24
|
+
page: 1
|
|
25
|
+
// typeOf: { $eq: chevre.factory.actionType.CheckAction },
|
|
26
|
+
// project: { id: { $eq: project.id } },
|
|
27
|
+
// object: {
|
|
28
|
+
// movieTickets: {
|
|
29
|
+
// identifier: { $eq: '0947524082' },
|
|
30
|
+
// serviceOutput: { reservationFor: { id: { $eq: 'clhvvbpyn' } } }
|
|
31
|
+
// }
|
|
32
|
+
// }
|
|
33
|
+
// instrument: { transactionNumber: { $eq: 'x' } },
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
console.log('tasks:', tasks);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
main()
|
|
40
|
+
.then(() => {
|
|
41
|
+
console.log('success!');
|
|
42
|
+
})
|
|
43
|
+
.catch(console.error);
|
|
@@ -8,7 +8,10 @@ const modelName = 'Task';
|
|
|
8
8
|
exports.modelName = modelName;
|
|
9
9
|
const schemaDefinition = {
|
|
10
10
|
identifier: String,
|
|
11
|
-
project:
|
|
11
|
+
project: {
|
|
12
|
+
type: mongoose_1.SchemaTypes.Mixed,
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
12
15
|
name: String,
|
|
13
16
|
status: String,
|
|
14
17
|
runsAt: Date,
|
|
@@ -191,21 +194,22 @@ const indexes = [
|
|
|
191
194
|
{ status: 1, name: 1, numberOfTried: 1, runsAt: 1 },
|
|
192
195
|
{ name: 'executeOneByName' }
|
|
193
196
|
],
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
197
|
+
// 廃止(2024-04-23~)
|
|
198
|
+
// [
|
|
199
|
+
// {
|
|
200
|
+
// 'project.id': 1,
|
|
201
|
+
// status: 1,
|
|
202
|
+
// name: 1,
|
|
203
|
+
// numberOfTried: 1,
|
|
204
|
+
// runsAt: 1
|
|
205
|
+
// },
|
|
206
|
+
// {
|
|
207
|
+
// name: 'executeOneByName-v2',
|
|
208
|
+
// partialFilterExpression: {
|
|
209
|
+
// 'project.id': { $exists: true }
|
|
210
|
+
// }
|
|
211
|
+
// }
|
|
212
|
+
// ],
|
|
209
213
|
[
|
|
210
214
|
{ status: 1, remainingNumberOfTries: 1, lastTriedAt: 1 },
|
|
211
215
|
{
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
/// <reference types="mongoose/types/validation" />
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
import type { Connection, Model } from 'mongoose';
|
|
25
|
+
import type { Connection, Model, UpdateWriteOpResult } from 'mongoose';
|
|
26
26
|
import * as factory from '../factory';
|
|
27
27
|
interface IAggregationByStatus {
|
|
28
28
|
taskCount: number;
|
|
@@ -46,6 +46,7 @@ interface IOptionOnCreate {
|
|
|
46
46
|
}
|
|
47
47
|
export type IExecutableTaskKeys = 'data' | 'id' | 'name' | 'status' | 'numberOfTried' | 'project' | 'remainingNumberOfTries' | 'runsAt' | 'expires';
|
|
48
48
|
export type IExecutableTask<T extends factory.taskName> = Pick<factory.task.ITask<T>, IExecutableTaskKeys>;
|
|
49
|
+
type IDelayedTask = Pick<factory.task.ITask<factory.taskName>, 'id' | 'name' | 'status'>;
|
|
49
50
|
/**
|
|
50
51
|
* タスクリポジトリ
|
|
51
52
|
*/
|
|
@@ -98,16 +99,18 @@ export declare class MongoRepository {
|
|
|
98
99
|
*/
|
|
99
100
|
$nin?: factory.taskName[];
|
|
100
101
|
};
|
|
101
|
-
}): Promise<
|
|
102
|
+
}): Promise<(import("mongoose").Document<unknown, {}, IDelayedTask> & Omit<IDelayedTask & {
|
|
103
|
+
_id: import("mongoose").Types.ObjectId;
|
|
104
|
+
}, never>)[]>;
|
|
102
105
|
retry(params: {
|
|
103
106
|
intervalInMinutes: number;
|
|
104
|
-
}): Promise<
|
|
107
|
+
}): Promise<UpdateWriteOpResult>;
|
|
105
108
|
abortOne(params: {
|
|
106
109
|
intervalInMinutes: number;
|
|
107
110
|
}): Promise<factory.task.ITask<factory.taskName> | null>;
|
|
108
111
|
abortMany(params: {
|
|
109
112
|
intervalInMinutes: number;
|
|
110
|
-
}): Promise<
|
|
113
|
+
}): Promise<UpdateWriteOpResult>;
|
|
111
114
|
pushExecutionResultById(id: string, status: factory.taskStatus, executionResult: factory.task.IExecutionResult): Promise<void>;
|
|
112
115
|
/**
|
|
113
116
|
* 特定タスク検索
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -461,15 +461,17 @@ class MongoRepository {
|
|
|
461
461
|
const lastTriedAtShoudBeLessThan = moment()
|
|
462
462
|
.add(-params.intervalInMinutes, 'minutes')
|
|
463
463
|
.toDate();
|
|
464
|
-
|
|
465
|
-
status: factory.taskStatus.Running,
|
|
464
|
+
return this.taskModel.updateMany({
|
|
465
|
+
status: { $eq: factory.taskStatus.Running },
|
|
466
466
|
lastTriedAt: {
|
|
467
467
|
$type: 'date',
|
|
468
468
|
$lt: lastTriedAtShoudBeLessThan
|
|
469
469
|
},
|
|
470
470
|
remainingNumberOfTries: { $gt: 0 }
|
|
471
471
|
}, {
|
|
472
|
-
|
|
472
|
+
$set: {
|
|
473
|
+
status: factory.taskStatus.Ready // 実行前に変更
|
|
474
|
+
}
|
|
473
475
|
})
|
|
474
476
|
.exec();
|
|
475
477
|
});
|
|
@@ -480,15 +482,17 @@ class MongoRepository {
|
|
|
480
482
|
.add(-params.intervalInMinutes, 'minutes')
|
|
481
483
|
.toDate();
|
|
482
484
|
const doc = yield this.taskModel.findOneAndUpdate({
|
|
483
|
-
status: factory.taskStatus.Running,
|
|
485
|
+
status: { $eq: factory.taskStatus.Running },
|
|
484
486
|
lastTriedAt: {
|
|
485
487
|
$type: 'date',
|
|
486
488
|
$lt: lastTriedAtShoudBeLessThan
|
|
487
489
|
},
|
|
488
|
-
remainingNumberOfTries: 0
|
|
490
|
+
remainingNumberOfTries: { $eq: 0 }
|
|
489
491
|
}, {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
+
$set: {
|
|
493
|
+
status: factory.taskStatus.Aborted,
|
|
494
|
+
dateAborted: new Date()
|
|
495
|
+
}
|
|
492
496
|
}, { new: true })
|
|
493
497
|
.exec();
|
|
494
498
|
if (doc === null) {
|
|
@@ -503,16 +507,18 @@ class MongoRepository {
|
|
|
503
507
|
const lastTriedAtShoudBeLessThan = moment()
|
|
504
508
|
.add(-params.intervalInMinutes, 'minutes')
|
|
505
509
|
.toDate();
|
|
506
|
-
|
|
507
|
-
status: factory.taskStatus.Running,
|
|
510
|
+
return this.taskModel.updateMany({
|
|
511
|
+
status: { $eq: factory.taskStatus.Running },
|
|
508
512
|
lastTriedAt: {
|
|
509
513
|
$type: 'date',
|
|
510
514
|
$lt: lastTriedAtShoudBeLessThan
|
|
511
515
|
},
|
|
512
|
-
remainingNumberOfTries: 0
|
|
516
|
+
remainingNumberOfTries: { $eq: 0 }
|
|
513
517
|
}, {
|
|
514
|
-
|
|
515
|
-
|
|
518
|
+
$set: {
|
|
519
|
+
status: factory.taskStatus.Aborted,
|
|
520
|
+
dateAborted: new Date()
|
|
521
|
+
}
|
|
516
522
|
})
|
|
517
523
|
.exec();
|
|
518
524
|
});
|
package/package.json
CHANGED