@chevre/domain 22.11.0-alpha.24 → 22.11.0-alpha.25
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/example/src/chevre/task/countTasks.ts +2 -1
- package/lib/chevre/repo/task.d.ts +6 -3
- package/lib/chevre/repo/task.js +11 -9
- package/lib/chevre/service/task.d.ts +6 -6
- package/lib/chevre/service/task.js +6 -4
- package/package.json +1 -1
- package/example/src/chevre/executeOneTask.ts +0 -41
- package/example/src/chevre/executeTaskIfExists.ts +0 -80
|
@@ -36,7 +36,8 @@ async function main() {
|
|
|
36
36
|
|
|
37
37
|
const runningTasksCountResult = await taskRepo.count({
|
|
38
38
|
limit: 100,
|
|
39
|
-
status: { $eq: chevre.factory.taskStatus.Running }
|
|
39
|
+
status: { $eq: chevre.factory.taskStatus.Running },
|
|
40
|
+
runsThrough: new Date()
|
|
40
41
|
});
|
|
41
42
|
console.log('runningTasksCountResult:', runningTasksCountResult);
|
|
42
43
|
},
|
|
@@ -86,9 +86,8 @@ export declare class TaskRepo {
|
|
|
86
86
|
* Readyのタスクをname指定でひとつRunningに変更する
|
|
87
87
|
*/
|
|
88
88
|
executeOneIfExists(params: {
|
|
89
|
-
name
|
|
90
|
-
$eq
|
|
91
|
-
$nin?: factory.taskName[];
|
|
89
|
+
name: {
|
|
90
|
+
$eq: factory.taskName;
|
|
92
91
|
};
|
|
93
92
|
executor: {
|
|
94
93
|
name: string;
|
|
@@ -96,6 +95,10 @@ export declare class TaskRepo {
|
|
|
96
95
|
runsAt: {
|
|
97
96
|
$lt: Date;
|
|
98
97
|
};
|
|
98
|
+
sort: {
|
|
99
|
+
numberOfTried?: factory.sortType;
|
|
100
|
+
runsAt: factory.sortType;
|
|
101
|
+
};
|
|
99
102
|
}): Promise<IExecutableTask<factory.taskName> | null>;
|
|
100
103
|
/**
|
|
101
104
|
* add(2025-03-16~)
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -30,10 +30,10 @@ const task_2 = require("./mongoose/schemas/task");
|
|
|
30
30
|
/**
|
|
31
31
|
* タスク実行時のソート条件
|
|
32
32
|
*/
|
|
33
|
-
const sortOrder4executionOfTasks = {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
33
|
+
// const sortOrder4executionOfTasks: { [key in keyof factory.task.IAttributes<factory.taskName>]?: factory.sortType } = {
|
|
34
|
+
// numberOfTried: factory.sortType.Ascending, // トライ回数の少なさ優先
|
|
35
|
+
// runsAt: factory.sortType.Ascending // 実行予定日時の早さ優先
|
|
36
|
+
// };
|
|
37
37
|
const executableTaskProjection = {
|
|
38
38
|
_id: 0,
|
|
39
39
|
id: { $toString: '$_id' },
|
|
@@ -394,15 +394,17 @@ class TaskRepo {
|
|
|
394
394
|
*/
|
|
395
395
|
executeOneIfExists(params) {
|
|
396
396
|
return __awaiter(this, void 0, void 0, function* () {
|
|
397
|
-
var _a
|
|
397
|
+
var _a;
|
|
398
398
|
if (!(params.runsAt.$lt instanceof Date)) {
|
|
399
399
|
throw new factory.errors.Argument('runsAt.$lt', 'must be Date');
|
|
400
400
|
}
|
|
401
401
|
const nameEq = (_a = params.name) === null || _a === void 0 ? void 0 : _a.$eq;
|
|
402
|
-
const nameNin =
|
|
403
|
-
const doc = yield this.taskModel.findOneAndUpdate(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string'
|
|
402
|
+
// const nameNin = params.name?.$nin;
|
|
403
|
+
const doc = yield this.taskModel.findOneAndUpdate(Object.assign({ status: { $eq: factory.taskStatus.Ready }, runsAt: { $lt: params.runsAt.$lt } }, (typeof nameEq === 'string')
|
|
404
404
|
? {
|
|
405
|
-
name: Object.assign(
|
|
405
|
+
name: Object.assign({}, (typeof nameEq === 'string') ? { $eq: nameEq } : undefined
|
|
406
|
+
// ...(Array.isArray(nameNin)) ? { $nin: nameNin } : undefined
|
|
407
|
+
)
|
|
406
408
|
}
|
|
407
409
|
: undefined), {
|
|
408
410
|
$set: {
|
|
@@ -415,7 +417,7 @@ class TaskRepo {
|
|
|
415
417
|
numberOfTried: 1 // トライ回数増やす
|
|
416
418
|
}
|
|
417
419
|
}, { new: true, projection: executableTaskProjection })
|
|
418
|
-
.sort(
|
|
420
|
+
.sort(params.sort)
|
|
419
421
|
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
420
422
|
.lean() // lean(2024-09-26~)
|
|
421
423
|
.exec();
|
|
@@ -23,13 +23,9 @@ declare function executeById(params: (IReadyTask | IRunningTask) & {
|
|
|
23
23
|
name: string;
|
|
24
24
|
};
|
|
25
25
|
}, next?: INextFunction): IOperation<void>;
|
|
26
|
-
/**
|
|
27
|
-
* support no name(2025-03-04~)
|
|
28
|
-
*/
|
|
29
26
|
declare function executeOneIfExists(params: {
|
|
30
|
-
name
|
|
31
|
-
$eq
|
|
32
|
-
$nin?: factory.taskName[];
|
|
27
|
+
name: {
|
|
28
|
+
$eq: factory.taskName;
|
|
33
29
|
};
|
|
34
30
|
executor: {
|
|
35
31
|
/**
|
|
@@ -40,5 +36,9 @@ declare function executeOneIfExists(params: {
|
|
|
40
36
|
runsAt: {
|
|
41
37
|
$lt: Date;
|
|
42
38
|
};
|
|
39
|
+
sort: {
|
|
40
|
+
numberOfTried?: factory.sortType;
|
|
41
|
+
runsAt: factory.sortType;
|
|
42
|
+
};
|
|
43
43
|
}): IOperation<void>;
|
|
44
44
|
export { executeById, executeOneIfExists };
|
|
@@ -45,9 +45,6 @@ function executeById(params, next) {
|
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
|
-
/**
|
|
49
|
-
* support no name(2025-03-04~)
|
|
50
|
-
*/
|
|
51
48
|
function executeOneIfExists(params) {
|
|
52
49
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
53
50
|
var _a;
|
|
@@ -56,7 +53,12 @@ function executeOneIfExists(params) {
|
|
|
56
53
|
// tslint:disable-next-line:no-null-keyword
|
|
57
54
|
let task = null;
|
|
58
55
|
try {
|
|
59
|
-
task = yield taskRepo.executeOneIfExists(
|
|
56
|
+
task = yield taskRepo.executeOneIfExists({
|
|
57
|
+
executor: { name: params.executor.name },
|
|
58
|
+
runsAt: { $lt: params.runsAt.$lt },
|
|
59
|
+
name: params.name,
|
|
60
|
+
sort: params.sort
|
|
61
|
+
});
|
|
60
62
|
debug('executable task found.', task, params.runsAt.$lt);
|
|
61
63
|
}
|
|
62
64
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import * as moment from 'moment';
|
|
3
|
-
import * as mongoose from 'mongoose';
|
|
4
|
-
|
|
5
|
-
import { chevre } from '../../../lib/index';
|
|
6
|
-
|
|
7
|
-
// const project = { id: String(process.env.PROJECT_ID) };
|
|
8
|
-
|
|
9
|
-
async function main() {
|
|
10
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
11
|
-
|
|
12
|
-
const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
|
|
13
|
-
const task = await taskRepo.executeOneIfExists({
|
|
14
|
-
name: {
|
|
15
|
-
$nin: [
|
|
16
|
-
chevre.factory.taskName.DeleteTransaction,
|
|
17
|
-
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
18
|
-
chevre.factory.taskName.ImportEventsFromCOA,
|
|
19
|
-
chevre.factory.taskName.AcceptCOAOffer,
|
|
20
|
-
chevre.factory.taskName.CheckMovieTicket,
|
|
21
|
-
chevre.factory.taskName.AuthorizePayment,
|
|
22
|
-
chevre.factory.taskName.PublishPaymentUrl
|
|
23
|
-
]
|
|
24
|
-
},
|
|
25
|
-
executor: { name: 'sample' },
|
|
26
|
-
runsAt: {
|
|
27
|
-
$lt: moment()
|
|
28
|
-
// tslint:disable-next-line:no-magic-numbers
|
|
29
|
-
.add(-2, 'years')
|
|
30
|
-
// .add(-60, 'seconds')
|
|
31
|
-
.toDate()
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
// tslint:disable-next-line:no-null-keyword
|
|
36
|
-
console.dir(task, { depth: null });
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
main()
|
|
40
|
-
.then()
|
|
41
|
-
.catch(console.error);
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// tslint:disable:no-console
|
|
2
|
-
import { chevre } from '../../../lib/index';
|
|
3
|
-
|
|
4
|
-
import * as mongoose from 'mongoose';
|
|
5
|
-
import * as redis from 'redis';
|
|
6
|
-
|
|
7
|
-
export async function executeTaskIfExists() {
|
|
8
|
-
const redisClient = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
|
|
9
|
-
socket: {
|
|
10
|
-
port: Number(<string>process.env.REDIS_PORT),
|
|
11
|
-
host: <string>process.env.REDIS_HOST
|
|
12
|
-
},
|
|
13
|
-
password: <string>process.env.REDIS_KEY
|
|
14
|
-
});
|
|
15
|
-
await redisClient.connect();
|
|
16
|
-
|
|
17
|
-
await mongoose.connect(<string>process.env.MONGOLAB_URI);
|
|
18
|
-
|
|
19
|
-
let count = 0;
|
|
20
|
-
|
|
21
|
-
const MAX_NUBMER_OF_PARALLEL_TASKS = 1;
|
|
22
|
-
const INTERVAL_MILLISECONDS = 1000;
|
|
23
|
-
|
|
24
|
-
setInterval(
|
|
25
|
-
async () => {
|
|
26
|
-
if (count > MAX_NUBMER_OF_PARALLEL_TASKS) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
count += 1;
|
|
31
|
-
|
|
32
|
-
try {
|
|
33
|
-
console.log('executing...', count);
|
|
34
|
-
await (await chevre.service.task.createService()).executeOneIfExists({
|
|
35
|
-
// name: chevre.factory.taskName.AggregateScreeningEvent,
|
|
36
|
-
executor: { name: 'sample' },
|
|
37
|
-
runsAt: { $lt: new Date() },
|
|
38
|
-
name: {
|
|
39
|
-
$nin: [
|
|
40
|
-
chevre.factory.taskName.DeleteTransaction,
|
|
41
|
-
chevre.factory.taskName.ImportEventCapacitiesFromCOA,
|
|
42
|
-
chevre.factory.taskName.ImportEventsFromCOA,
|
|
43
|
-
chevre.factory.taskName.AcceptCOAOffer,
|
|
44
|
-
chevre.factory.taskName.CheckMovieTicket,
|
|
45
|
-
chevre.factory.taskName.AuthorizePayment,
|
|
46
|
-
chevre.factory.taskName.PublishPaymentUrl
|
|
47
|
-
]
|
|
48
|
-
}
|
|
49
|
-
})({
|
|
50
|
-
connection: mongoose.connection,
|
|
51
|
-
redisClient,
|
|
52
|
-
credentials: {
|
|
53
|
-
sendGrid: await chevre.credentials.SendGrid.createInstance({ apiKey: 'xxx' })
|
|
54
|
-
},
|
|
55
|
-
settings: new chevre.settings.Settings({
|
|
56
|
-
deliverOrderLimit: 1,
|
|
57
|
-
abortedTasksWithoutReport: [],
|
|
58
|
-
coa: { timeout: 1000 },
|
|
59
|
-
gmo: { timeout: 1000, timeoutBackground: 1000, useFetch: true },
|
|
60
|
-
movieticketReserve: { timeout: 1000, timeoutCheck: 1000, minIntervalBetweenPayAndRefund: 0 },
|
|
61
|
-
numTryConfirmReserveTransaction: 10,
|
|
62
|
-
useExperimentalFeature: false
|
|
63
|
-
})
|
|
64
|
-
});
|
|
65
|
-
console.log('executed', count);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.error(error);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
count -= 1;
|
|
71
|
-
},
|
|
72
|
-
INTERVAL_MILLISECONDS
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
executeTaskIfExists()
|
|
77
|
-
.then(() => {
|
|
78
|
-
console.log('success!');
|
|
79
|
-
})
|
|
80
|
-
.catch(console.error);
|