@chevre/domain 22.11.0-alpha.26 → 22.11.0-alpha.28
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/setting.d.ts +4 -0
- package/lib/chevre/repo/task.d.ts +1 -1
- package/lib/chevre/repo/task.js +3 -2
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.d.ts +4 -1
- package/lib/chevre/service/taskHandler/onOperationFailed/informTaskIfNeeded.js +66 -43
- package/lib/chevre/service/taskHandler/onOperationFailed.js +9 -3
- package/package.json +2 -2
|
@@ -22,6 +22,10 @@ interface IOnTaskStatusChanged {
|
|
|
22
22
|
* 分析連携するtaskNameリスト
|
|
23
23
|
*/
|
|
24
24
|
informTaskNames?: factory.taskName[];
|
|
25
|
+
/**
|
|
26
|
+
* 分析連携するtaskStatusリスト
|
|
27
|
+
*/
|
|
28
|
+
informTaskStatuses?: factory.taskStatus[];
|
|
25
29
|
}
|
|
26
30
|
interface IOnEventChanged {
|
|
27
31
|
informEvent2agg?: factory.project.IInformParams[];
|
package/lib/chevre/repo/task.js
CHANGED
|
@@ -486,8 +486,9 @@ class TaskRepo {
|
|
|
486
486
|
remainingNumberOfTries: -1, // 残りトライ可能回数減らす
|
|
487
487
|
numberOfTried: 1 // トライ回数増やす
|
|
488
488
|
}
|
|
489
|
-
}, { new: true, projection })
|
|
490
|
-
|
|
489
|
+
}, Object.assign({ new: true, projection }, (typeof params.sort.runsAt === 'number')
|
|
490
|
+
? { sort: params.sort }
|
|
491
|
+
: undefined))
|
|
491
492
|
.setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
|
|
492
493
|
.lean()
|
|
493
494
|
.exec();
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import * as factory from '../../../factory';
|
|
2
2
|
import type { SettingRepo } from '../../../repo/setting';
|
|
3
3
|
import type { IExecutableTask, TaskRepo } from '../../../repo/task';
|
|
4
|
-
declare function informTaskIfNeeded(
|
|
4
|
+
declare function informTaskIfNeeded(params: {
|
|
5
|
+
task: IExecutableTask<factory.taskName>;
|
|
6
|
+
executionEndDate: Date;
|
|
7
|
+
}): (repos: {
|
|
5
8
|
setting: SettingRepo;
|
|
6
9
|
task: TaskRepo;
|
|
7
10
|
}) => Promise<void>;
|
|
@@ -13,66 +13,89 @@ exports.informTaskIfNeeded = informTaskIfNeeded;
|
|
|
13
13
|
const createDebug = require("debug");
|
|
14
14
|
const factory = require("../../../factory");
|
|
15
15
|
const debug = createDebug('chevre-domain:service:taskHandler:onOperationFailed');
|
|
16
|
-
function createInformTasks(
|
|
17
|
-
var _a, _b;
|
|
18
|
-
const
|
|
16
|
+
function createInformTasks(params) {
|
|
17
|
+
var _a, _b, _c;
|
|
18
|
+
const { task, setting, executionEndDate } = params;
|
|
19
19
|
const informTask = (_a = setting === null || setting === void 0 ? void 0 : setting.onTaskStatusChanged) === null || _a === void 0 ? void 0 : _a.informTask;
|
|
20
20
|
const informTaskNames = (_b = setting === null || setting === void 0 ? void 0 : setting.onTaskStatusChanged) === null || _b === void 0 ? void 0 : _b.informTaskNames;
|
|
21
|
+
const informTaskStatuses = (_c = setting === null || setting === void 0 ? void 0 : setting.onTaskStatusChanged) === null || _c === void 0 ? void 0 : _c.informTaskStatuses;
|
|
21
22
|
const informTasks = [];
|
|
22
23
|
if (Array.isArray(informTaskNames) && informTaskNames.includes(task.name)) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
if (typeof ((_a = informTaskParams.recipient) === null || _a === void 0 ? void 0 : _a.url) === 'string') {
|
|
34
|
-
const informActionAttributes = {
|
|
35
|
-
object: task4inform,
|
|
36
|
-
recipient: {
|
|
37
|
-
id: '',
|
|
38
|
-
name: String((_b = informTaskParams.recipient) === null || _b === void 0 ? void 0 : _b.name),
|
|
39
|
-
typeOf: factory.creativeWorkType.WebApplication
|
|
40
|
-
},
|
|
41
|
-
target: {
|
|
42
|
-
httpMethod: 'POST',
|
|
43
|
-
encodingType: factory.encodingFormat.Application.json,
|
|
44
|
-
typeOf: 'EntryPoint',
|
|
45
|
-
urlTemplate: informTaskParams.recipient.url
|
|
46
|
-
},
|
|
47
|
-
identifier: informIdentifier
|
|
24
|
+
if (Array.isArray(informTaskStatuses)) {
|
|
25
|
+
const { id, name, data, project, runsAt, remainingNumberOfTries } = task;
|
|
26
|
+
let task4inform;
|
|
27
|
+
if (remainingNumberOfTries <= 0) {
|
|
28
|
+
if (informTaskStatuses.includes(factory.taskStatus.Aborted)) {
|
|
29
|
+
const abortingTask = {
|
|
30
|
+
id, name, data, project, runsAt,
|
|
31
|
+
status: factory.taskStatus.Aborted,
|
|
32
|
+
typeOf: 'Task',
|
|
33
|
+
dateAborted: executionEndDate
|
|
48
34
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
35
|
+
task4inform = abortingTask;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
if (informTaskStatuses.includes(factory.taskStatus.Running)) {
|
|
40
|
+
const runningTask = {
|
|
41
|
+
id, name, data, project, runsAt,
|
|
42
|
+
status: factory.taskStatus.Running,
|
|
43
|
+
typeOf: 'Task'
|
|
44
|
+
};
|
|
45
|
+
task4inform = runningTask;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (task4inform !== undefined) {
|
|
49
|
+
const informIdentifier = `Task:${name}:${id}:${task4inform.status}`;
|
|
50
|
+
if (Array.isArray(informTask) && informTask.length > 0) {
|
|
51
|
+
informTask.forEach((informTaskParams) => {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
if (typeof ((_a = informTaskParams.recipient) === null || _a === void 0 ? void 0 : _a.url) === 'string') {
|
|
54
|
+
const informActionAttributes = {
|
|
55
|
+
object: task4inform,
|
|
56
|
+
recipient: {
|
|
57
|
+
id: '',
|
|
58
|
+
name: String((_b = informTaskParams.recipient) === null || _b === void 0 ? void 0 : _b.name),
|
|
59
|
+
typeOf: factory.creativeWorkType.WebApplication
|
|
60
|
+
},
|
|
61
|
+
target: {
|
|
62
|
+
httpMethod: 'POST',
|
|
63
|
+
encodingType: factory.encodingFormat.Application.json,
|
|
64
|
+
typeOf: 'EntryPoint',
|
|
65
|
+
urlTemplate: informTaskParams.recipient.url
|
|
66
|
+
},
|
|
67
|
+
identifier: informIdentifier
|
|
68
|
+
};
|
|
69
|
+
const description = `inform aborting tasks to agg service: ${name} ${id} ${task4inform.status}`;
|
|
70
|
+
informTasks.push({
|
|
71
|
+
project,
|
|
72
|
+
name: factory.taskName.TriggerWebhook,
|
|
73
|
+
status: factory.taskStatus.Ready,
|
|
74
|
+
runsAt: executionEndDate,
|
|
75
|
+
remainingNumberOfTries: 10,
|
|
76
|
+
numberOfTried: 0,
|
|
77
|
+
executionResults: [],
|
|
78
|
+
data: informActionAttributes,
|
|
79
|
+
description
|
|
80
|
+
});
|
|
81
|
+
}
|
|
60
82
|
});
|
|
61
83
|
}
|
|
62
|
-
}
|
|
84
|
+
}
|
|
63
85
|
}
|
|
64
86
|
}
|
|
65
87
|
return informTasks;
|
|
66
88
|
}
|
|
67
|
-
function informTaskIfNeeded(
|
|
89
|
+
function informTaskIfNeeded(params) {
|
|
68
90
|
return (repos) => __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
const
|
|
91
|
+
const { executionEndDate, task } = params;
|
|
92
|
+
const isAborting = task.status === factory.taskStatus.Running;
|
|
70
93
|
const useInform = isAborting
|
|
71
94
|
&& task.name !== factory.taskName.HandleNotification // nameで絞る
|
|
72
95
|
&& task.name !== factory.taskName.TriggerWebhook;
|
|
73
96
|
if (useInform) {
|
|
74
97
|
const setting = yield repos.setting.findOne({ project: { id: { $eq: '*' } } }, ['onTaskStatusChanged']);
|
|
75
|
-
const informTasks = createInformTasks(task, setting);
|
|
98
|
+
const informTasks = createInformTasks({ task, setting, executionEndDate });
|
|
76
99
|
debug('informTaskIfNeeded: creating inform tasks...', JSON.stringify(informTasks));
|
|
77
100
|
if (informTasks.length > 0) {
|
|
78
101
|
yield repos.task.saveMany(informTasks, { emitImmediately: true });
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.onOperationFailed = onOperationFailed;
|
|
13
13
|
const factory = require("../../factory");
|
|
14
14
|
const informTaskIfNeeded_1 = require("./onOperationFailed/informTaskIfNeeded");
|
|
15
|
+
const USE_INFORM_TASK_RUNNING = process.env.USE_INFORM_TASK_RUNNING === '1';
|
|
15
16
|
/**
|
|
16
17
|
* タスク実行失敗時処理
|
|
17
18
|
*/
|
|
@@ -22,12 +23,17 @@ function onOperationFailed(params) {
|
|
|
22
23
|
if (typeof error !== 'object') {
|
|
23
24
|
error = { message: String(error) };
|
|
24
25
|
}
|
|
26
|
+
const endDate = new Date();
|
|
25
27
|
// remainingNumberOfTries<=0ならAborted(2025-08-04~)
|
|
26
28
|
const isRetryable = task.remainingNumberOfTries > 0;
|
|
27
29
|
if (isRetryable) {
|
|
30
|
+
// 実験的に実行中タスク連携
|
|
31
|
+
if (USE_INFORM_TASK_RUNNING) {
|
|
32
|
+
yield (0, informTaskIfNeeded_1.informTaskIfNeeded)({ task, executionEndDate: endDate })(repos);
|
|
33
|
+
}
|
|
28
34
|
const result = {
|
|
29
35
|
executedAt: now,
|
|
30
|
-
endDate
|
|
36
|
+
endDate,
|
|
31
37
|
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
32
38
|
};
|
|
33
39
|
// 失敗してもここではステータスを戻さない(Runningのまま待機)
|
|
@@ -45,10 +51,10 @@ function onOperationFailed(params) {
|
|
|
45
51
|
// 設定されたnameの場合連携する
|
|
46
52
|
// もしここで連携タスク作成に失敗したとしても、再度Readyタスクとなりリトライされて、処理は冪等となる想定
|
|
47
53
|
// 最終的に、連携タスクが作成され、実行中タスクがAbortedとなればよい
|
|
48
|
-
yield (0, informTaskIfNeeded_1.informTaskIfNeeded)(task)(repos);
|
|
54
|
+
yield (0, informTaskIfNeeded_1.informTaskIfNeeded)({ task, executionEndDate: endDate })(repos);
|
|
49
55
|
const result = {
|
|
50
56
|
executedAt: now,
|
|
51
|
-
endDate
|
|
57
|
+
endDate,
|
|
52
58
|
error: Object.assign(Object.assign({}, error), { code: error.code, message: error.message, name: error.name, stack: error.stack })
|
|
53
59
|
};
|
|
54
60
|
yield repos.task.setExecutionResultAndStatus({
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@aws-sdk/client-cognito-identity-provider": "3.600.0",
|
|
13
13
|
"@aws-sdk/credential-providers": "3.600.0",
|
|
14
|
-
"@chevre/factory": "4.396.0-alpha.
|
|
14
|
+
"@chevre/factory": "4.396.0-alpha.4",
|
|
15
15
|
"@cinerino/sdk": "11.1.0",
|
|
16
16
|
"@motionpicture/coa-service": "9.6.0",
|
|
17
17
|
"@motionpicture/gmo-service": "5.3.0",
|
|
@@ -115,5 +115,5 @@
|
|
|
115
115
|
"postversion": "git push origin --tags",
|
|
116
116
|
"prepublishOnly": "npm run clean && npm run build && npm test && npm run doc"
|
|
117
117
|
},
|
|
118
|
-
"version": "22.11.0-alpha.
|
|
118
|
+
"version": "22.11.0-alpha.28"
|
|
119
119
|
}
|