@chevre/domain 21.2.0-alpha.20 → 21.2.0-alpha.22
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/chevre/repo/mongoose/schemas/task.d.ts +3 -0
- package/lib/chevre/repo/mongoose/schemas/task.js +1 -0
- package/lib/chevre/repo/task.d.ts +6 -0
- package/lib/chevre/repo/task.js +4 -2
- package/lib/chevre/service/task.d.ts +6 -0
- package/lib/chevre/service/task.js +15 -2
- package/package.json +1 -1
|
@@ -61,6 +61,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
61
61
|
remainingNumberOfTries?: number | undefined;
|
|
62
62
|
lastTriedAt?: Date | undefined;
|
|
63
63
|
numberOfTried?: number | undefined;
|
|
64
|
+
executor?: any;
|
|
64
65
|
dateAborted?: Date | undefined;
|
|
65
66
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
66
67
|
executionResults: any[];
|
|
@@ -72,6 +73,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
72
73
|
remainingNumberOfTries?: number | undefined;
|
|
73
74
|
lastTriedAt?: Date | undefined;
|
|
74
75
|
numberOfTried?: number | undefined;
|
|
76
|
+
executor?: any;
|
|
75
77
|
dateAborted?: Date | undefined;
|
|
76
78
|
}>> & Omit<import("mongoose").FlatRecord<{
|
|
77
79
|
executionResults: any[];
|
|
@@ -83,6 +85,7 @@ declare const schema: Schema<any, import("mongoose").Model<any, any, any, any, a
|
|
|
83
85
|
remainingNumberOfTries?: number | undefined;
|
|
84
86
|
lastTriedAt?: Date | undefined;
|
|
85
87
|
numberOfTried?: number | undefined;
|
|
88
|
+
executor?: any;
|
|
86
89
|
dateAborted?: Date | undefined;
|
|
87
90
|
}> & {
|
|
88
91
|
_id: import("mongoose").Types.ObjectId;
|
|
@@ -33,9 +33,15 @@ export declare class MongoRepository {
|
|
|
33
33
|
createInformTaskIfNotExist(params: factory.task.IAttributes<factory.taskName.TriggerWebhook>, options: IOptionOnCreate): Promise<void>;
|
|
34
34
|
executeById(params: {
|
|
35
35
|
id: string;
|
|
36
|
+
executor: {
|
|
37
|
+
name: string;
|
|
38
|
+
};
|
|
36
39
|
}): Promise<factory.task.ITask<factory.taskName> | null>;
|
|
37
40
|
executeOneByName<T extends factory.taskName>(params: {
|
|
38
41
|
name: T;
|
|
42
|
+
executor: {
|
|
43
|
+
name: string;
|
|
44
|
+
};
|
|
39
45
|
}): Promise<factory.task.ITask<T> | null>;
|
|
40
46
|
retry(params: {
|
|
41
47
|
intervalInMinutes: number;
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -211,7 +211,8 @@ class MongoRepository {
|
|
|
211
211
|
$inc: {
|
|
212
212
|
remainingNumberOfTries: -1,
|
|
213
213
|
numberOfTried: 1 // トライ回数増やす
|
|
214
|
-
}
|
|
214
|
+
},
|
|
215
|
+
executor: params.executor
|
|
215
216
|
}, { new: true })
|
|
216
217
|
.exec();
|
|
217
218
|
if (doc === null) {
|
|
@@ -233,7 +234,8 @@ class MongoRepository {
|
|
|
233
234
|
$inc: {
|
|
234
235
|
remainingNumberOfTries: -1,
|
|
235
236
|
numberOfTried: 1 // トライ回数増やす
|
|
236
|
-
}
|
|
237
|
+
},
|
|
238
|
+
executor: params.executor
|
|
237
239
|
}, { new: true })
|
|
238
240
|
.sort(sortOrder4executionOfTasks)
|
|
239
241
|
.exec();
|
|
@@ -18,12 +18,18 @@ export type TaskOperation<T> = (repos: {
|
|
|
18
18
|
export type IOperation<T> = (settings: IConnectionSettings) => Promise<T>;
|
|
19
19
|
export declare function executeById(params: {
|
|
20
20
|
id: string;
|
|
21
|
+
executor?: {
|
|
22
|
+
name: string;
|
|
23
|
+
};
|
|
21
24
|
}): IOperation<void>;
|
|
22
25
|
/**
|
|
23
26
|
* タスク名でタスクをひとつ実行する
|
|
24
27
|
*/
|
|
25
28
|
export declare function executeByName<T extends factory.taskName>(params: {
|
|
26
29
|
name: T;
|
|
30
|
+
executor?: {
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
27
33
|
}): IOperation<void>;
|
|
28
34
|
/**
|
|
29
35
|
* タスクを実行する
|
|
@@ -20,14 +20,21 @@ const NotificationService = require("./notification");
|
|
|
20
20
|
const factory_1 = require("./notification/factory");
|
|
21
21
|
const settings_1 = require("../settings");
|
|
22
22
|
const debug = createDebug('chevre-domain:service:task');
|
|
23
|
+
const DEFAULT_EXECUTOR_NAME = `${process.env.GAE_APPLICATION}:${process.env.GAE_INSTANCE}:${process.env.GAE_SERVICE}:jobs`;
|
|
23
24
|
function executeById(params) {
|
|
24
25
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
25
27
|
const taskRepo = new task_1.MongoRepository(settings.connection);
|
|
26
28
|
// 未実行のタスクを取得
|
|
27
29
|
// tslint:disable-next-line:no-null-keyword
|
|
28
30
|
let task = null;
|
|
29
31
|
try {
|
|
30
|
-
task = yield taskRepo.executeById({
|
|
32
|
+
task = yield taskRepo.executeById({
|
|
33
|
+
id: params.id,
|
|
34
|
+
executor: {
|
|
35
|
+
name: (typeof ((_a = params.executor) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? params.executor.name : DEFAULT_EXECUTOR_NAME
|
|
36
|
+
}
|
|
37
|
+
});
|
|
31
38
|
}
|
|
32
39
|
catch (error) {
|
|
33
40
|
// tslint:disable-next-line:no-single-line-block-comment
|
|
@@ -46,12 +53,18 @@ exports.executeById = executeById;
|
|
|
46
53
|
*/
|
|
47
54
|
function executeByName(params) {
|
|
48
55
|
return (settings) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
var _a;
|
|
49
57
|
const taskRepo = new task_1.MongoRepository(settings.connection);
|
|
50
58
|
// 未実行のタスクを取得
|
|
51
59
|
// tslint:disable-next-line:no-null-keyword
|
|
52
60
|
let task = null;
|
|
53
61
|
try {
|
|
54
|
-
task = yield taskRepo.executeOneByName(
|
|
62
|
+
task = yield taskRepo.executeOneByName({
|
|
63
|
+
name: params.name,
|
|
64
|
+
executor: {
|
|
65
|
+
name: (typeof ((_a = params.executor) === null || _a === void 0 ? void 0 : _a.name) === 'string') ? params.executor.name : DEFAULT_EXECUTOR_NAME
|
|
66
|
+
}
|
|
67
|
+
});
|
|
55
68
|
}
|
|
56
69
|
catch (error) {
|
|
57
70
|
// tslint:disable-next-line:no-single-line-block-comment
|
package/package.json
CHANGED