@chevre/domain 25.2.0-alpha.46 → 25.2.0-alpha.48

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,67 @@
1
+ import type { Connection, UpdateWriteOpResult } from 'mongoose';
2
+ import { factory } from '../factory';
3
+ import { IModel } from './mongoose/schemas/asyncAction';
4
+ import type { IExecutableTask } from '../taskSettings';
5
+ type ISavingTask = Pick<factory.task.IAttributes<factory.taskName>, 'alternateName' | 'data' | 'description' | 'executionResults' | 'expires' | 'identifier' | 'name' | 'project' | 'runsAt' | 'status'> & {
6
+ expires: Date;
7
+ };
8
+ export type IExecutableAsyncAction = Pick<IExecutableTask<factory.taskName>, 'data' | 'expires' | 'id' | 'name' | 'project' | 'runsAt' | 'status'>;
9
+ /**
10
+ * 非同期アクションリポジトリ
11
+ */
12
+ export declare class AsyncActionRepo {
13
+ readonly asyncActionModel: IModel;
14
+ constructor(connection: Connection);
15
+ /**
16
+ * Readyタスクをひとつ追加する
17
+ */
18
+ addReadyAsyncAction(params: Pick<ISavingTask, 'data' | 'expires' | 'name' | 'project' | 'runsAt'> & {
19
+ alternateName?: never;
20
+ identifier?: never;
21
+ }): Promise<{
22
+ id: string;
23
+ }>;
24
+ /**
25
+ * Ready -> Running
26
+ */
27
+ executeAsyncActionById(params: {
28
+ id: string;
29
+ executor: {
30
+ name: string;
31
+ };
32
+ }): Promise<IExecutableAsyncAction | null>;
33
+ /**
34
+ * Readyのままで期限切れのタスクをExpiredに変更する
35
+ */
36
+ makeExpiredMany(params: {
37
+ expiresLt: Date;
38
+ }): Promise<UpdateWriteOpResult>;
39
+ /**
40
+ * taskNameに関わらず、Runningのまま放置された非同期アクションをAbortedに変更する
41
+ */
42
+ abortMany(params: {
43
+ intervalInMinutes: number;
44
+ }): Promise<UpdateWriteOpResult>;
45
+ /**
46
+ * タスクIDから実行結果とステータスを保管する
47
+ * Abortedの場合、dateAbortedもセットする
48
+ */
49
+ setExecutionResultAndStatus(params: {
50
+ /**
51
+ * タスクID
52
+ */
53
+ id: string;
54
+ }, update: {
55
+ status: factory.taskStatus.Executed | factory.taskStatus.Aborted;
56
+ executionResult: factory.task.IExecutionResult;
57
+ }): Promise<void>;
58
+ /**
59
+ * 不要なタスクを削除する
60
+ */
61
+ deleteRunsAtPassedCertainPeriod(params: {
62
+ runsAt: {
63
+ $lt: Date;
64
+ };
65
+ }): Promise<import("mongodb").DeleteResult>;
66
+ }
67
+ export {};
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AsyncActionRepo = void 0;
7
+ const moment_1 = __importDefault(require("moment"));
8
+ const factory_1 = require("../factory");
9
+ const settings_1 = require("../settings");
10
+ const asyncAction_1 = require("./mongoose/schemas/asyncAction");
11
+ const executableTaskProjection = {
12
+ _id: 0,
13
+ id: { $toString: '$_id' },
14
+ // 必要最低限にprojection(2024-04-23~)
15
+ data: 1,
16
+ name: 1,
17
+ status: 1,
18
+ project: 1,
19
+ runsAt: 1,
20
+ expires: 1
21
+ };
22
+ /**
23
+ * 非同期アクションリポジトリ
24
+ */
25
+ class AsyncActionRepo {
26
+ asyncActionModel;
27
+ constructor(connection) {
28
+ this.asyncActionModel = connection.model(asyncAction_1.modelName, (0, asyncAction_1.createSchema)());
29
+ }
30
+ /**
31
+ * Readyタスクをひとつ追加する
32
+ */
33
+ async addReadyAsyncAction(params) {
34
+ const { expires } = params;
35
+ if (!(expires instanceof Date)) {
36
+ throw new factory_1.factory.errors.Argument('expires', 'must be Date');
37
+ }
38
+ const savingTask = {
39
+ ...params,
40
+ status: factory_1.factory.taskStatus.Ready,
41
+ executionResults: []
42
+ };
43
+ const result = await this.asyncActionModel.insertMany(savingTask, { rawResult: true });
44
+ const id = result.insertedIds?.[0]?.toHexString();
45
+ if (typeof id !== 'string') {
46
+ throw new factory_1.factory.errors.Internal('task not saved');
47
+ }
48
+ return { id };
49
+ }
50
+ /**
51
+ * Ready -> Running
52
+ */
53
+ async executeAsyncActionById(params) {
54
+ const now = new Date();
55
+ const doc = await this.asyncActionModel.findOneAndUpdate({
56
+ _id: { $eq: params.id },
57
+ status: { $eq: factory_1.factory.taskStatus.Ready }, // Readyのものしか実行しない
58
+ runsAt: { $lt: now },
59
+ expires: { $exists: true, $gt: now }, // ワンタイムタスクなのでexpiresは必ず存在する
60
+ }, {
61
+ $set: {
62
+ status: factory_1.factory.taskStatus.Running, // 実行中に変更
63
+ lastTriedAt: now,
64
+ executor: params.executor
65
+ },
66
+ }, { new: true, projection: executableTaskProjection })
67
+ .setOptions({ maxTimeMS: settings_1.MONGO_MAX_TIME_MS })
68
+ .lean() // lean(2024-09-26~)
69
+ .exec();
70
+ if (doc === null) {
71
+ return null;
72
+ }
73
+ return doc;
74
+ }
75
+ /**
76
+ * Readyのままで期限切れのタスクをExpiredに変更する
77
+ */
78
+ async makeExpiredMany(params) {
79
+ const { expiresLt } = params;
80
+ if (!(expiresLt instanceof Date)) {
81
+ throw new factory_1.factory.errors.Argument('expiresLt', 'must be Date');
82
+ }
83
+ return this.asyncActionModel.updateMany({
84
+ status: { $eq: factory_1.factory.taskStatus.Ready },
85
+ expires: { $exists: true, $lt: expiresLt }
86
+ }, {
87
+ $set: {
88
+ status: factory_1.factory.taskStatus.Expired
89
+ }
90
+ })
91
+ .exec();
92
+ }
93
+ /**
94
+ * taskNameに関わらず、Runningのまま放置された非同期アクションをAbortedに変更する
95
+ */
96
+ async abortMany(params) {
97
+ const lastTriedAtShoudBeLessThan = (0, moment_1.default)()
98
+ .add(-params.intervalInMinutes, 'minutes')
99
+ .toDate();
100
+ return this.asyncActionModel.updateMany({
101
+ status: { $eq: factory_1.factory.taskStatus.Running },
102
+ lastTriedAt: {
103
+ $exists: true,
104
+ $lt: lastTriedAtShoudBeLessThan
105
+ }
106
+ }, {
107
+ $set: {
108
+ status: factory_1.factory.taskStatus.Aborted,
109
+ dateAborted: new Date()
110
+ }
111
+ })
112
+ .exec();
113
+ }
114
+ /**
115
+ * タスクIDから実行結果とステータスを保管する
116
+ * Abortedの場合、dateAbortedもセットする
117
+ */
118
+ async setExecutionResultAndStatus(params, update) {
119
+ const { id } = params;
120
+ const { status, executionResult } = update;
121
+ await this.asyncActionModel.updateOne({ _id: { $eq: id } }, {
122
+ $set: {
123
+ status,
124
+ ...(status === factory_1.factory.taskStatus.Aborted) ? { dateAborted: executionResult.endDate } : undefined // 2025-08-04~
125
+ },
126
+ $push: { executionResults: executionResult }
127
+ })
128
+ .exec();
129
+ }
130
+ /**
131
+ * 不要なタスクを削除する
132
+ */
133
+ async deleteRunsAtPassedCertainPeriod(params) {
134
+ return this.asyncActionModel.deleteMany({
135
+ runsAt: { $lt: params.runsAt.$lt },
136
+ status: {
137
+ $in: [
138
+ factory_1.factory.taskStatus.Aborted,
139
+ factory_1.factory.taskStatus.Executed,
140
+ factory_1.factory.taskStatus.Expired
141
+ ]
142
+ }
143
+ })
144
+ .exec();
145
+ }
146
+ }
147
+ exports.AsyncActionRepo = AsyncActionRepo;
@@ -0,0 +1,11 @@
1
+ import { IndexDefinition, IndexOptions, Model, Schema, SchemaDefinition } from 'mongoose';
2
+ import { IVirtuals } from '../virtuals';
3
+ import { factory } from '../../../factory';
4
+ type IDocType = Pick<factory.task.ITask<factory.taskName>, 'alternateName' | 'data' | 'dateAborted' | 'description' | 'executionResults' | 'executor' | 'expires' | 'identifier' | 'lastTriedAt' | 'name' | 'project' | 'runsAt' | 'status'>;
5
+ type IModel = Model<IDocType, Record<string, never>, Record<string, never>, IVirtuals>;
6
+ type ISchemaDefinition = SchemaDefinition<IDocType>;
7
+ type ISchema = Schema<IDocType, IModel, Record<string, never>, Record<string, never>, IVirtuals, Record<string, never>, ISchemaDefinition, IDocType>;
8
+ declare const modelName = "AsyncAction";
9
+ declare const indexes: [d: IndexDefinition, o: IndexOptions][];
10
+ declare function createSchema(): ISchema;
11
+ export { createSchema, IDocType, IModel, indexes, modelName };
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modelName = exports.indexes = void 0;
4
+ exports.createSchema = createSchema;
5
+ const mongoose_1 = require("mongoose");
6
+ const writeConcern_1 = require("../writeConcern");
7
+ const settings_1 = require("../../../settings");
8
+ const modelName = 'AsyncAction';
9
+ exports.modelName = modelName;
10
+ const schemaDefinition = {
11
+ alternateName: String, // add(2025-03-28~)
12
+ identifier: String,
13
+ description: String, // add(2025-03-30~)
14
+ project: { type: mongoose_1.SchemaTypes.Mixed, required: true },
15
+ name: { type: String, required: true },
16
+ status: { type: String, required: true },
17
+ runsAt: { type: Date, required: true },
18
+ expires: { type: Date, required: true },
19
+ lastTriedAt: Date,
20
+ executionResults: [mongoose_1.SchemaTypes.Mixed],
21
+ executor: mongoose_1.SchemaTypes.Mixed,
22
+ data: mongoose_1.SchemaTypes.Mixed,
23
+ dateAborted: Date,
24
+ // remainingNumberOfTries: { type: Number, required: true }, // ワンタイム前提につき不要
25
+ // numberOfTried: { type: Number, required: true }, // ワンタイム前提につき不要
26
+ };
27
+ const schemaOptions = {
28
+ autoIndex: settings_1.MONGO_AUTO_INDEX,
29
+ autoCreate: false,
30
+ collection: 'asyncActions',
31
+ id: true,
32
+ read: 'primary',
33
+ writeConcern: writeConcern_1.writeConcern,
34
+ strict: true,
35
+ strictQuery: false,
36
+ timestamps: false,
37
+ versionKey: false,
38
+ toJSON: {
39
+ getters: false,
40
+ virtuals: false,
41
+ minimize: false,
42
+ versionKey: false
43
+ },
44
+ toObject: {
45
+ getters: false,
46
+ virtuals: true,
47
+ minimize: false,
48
+ versionKey: false
49
+ }
50
+ };
51
+ const indexes = [
52
+ [
53
+ { 'project.id': 1, runsAt: -1 },
54
+ { name: 'projectId' }
55
+ ],
56
+ [
57
+ { name: 1, runsAt: -1 },
58
+ { name: 'asyncActionName' }
59
+ ],
60
+ [
61
+ { status: 1, runsAt: -1 },
62
+ { name: 'status' }
63
+ ],
64
+ [
65
+ { runsAt: -1 },
66
+ { name: 'runsAt' }
67
+ ],
68
+ [
69
+ { identifier: 1, runsAt: -1 },
70
+ {
71
+ name: 'identifier',
72
+ partialFilterExpression: {
73
+ identifier: { $exists: true }
74
+ }
75
+ }
76
+ ],
77
+ [
78
+ { dateAborted: 1, runsAt: -1 },
79
+ {
80
+ name: 'dateAborted',
81
+ partialFilterExpression: {
82
+ dateAborted: { $exists: true }
83
+ }
84
+ }
85
+ ],
86
+ [
87
+ { lastTriedAt: 1, runsAt: -1 },
88
+ {
89
+ name: 'lastTriedAt',
90
+ partialFilterExpression: {
91
+ lastTriedAt: { $exists: true }
92
+ }
93
+ }
94
+ ],
95
+ [
96
+ { expires: 1, runsAt: -1 },
97
+ {
98
+ name: 'expires',
99
+ partialFilterExpression: {
100
+ expires: { $exists: true }
101
+ }
102
+ }
103
+ ],
104
+ [
105
+ { status: 1, lastTriedAt: 1 },
106
+ {
107
+ name: 'abortMany',
108
+ partialFilterExpression: {
109
+ lastTriedAt: { $exists: true }
110
+ }
111
+ }
112
+ ],
113
+ [
114
+ { status: 1, expires: 1 },
115
+ {
116
+ name: 'makeExpiredMany',
117
+ partialFilterExpression: {
118
+ expires: { $exists: true }
119
+ }
120
+ }
121
+ ],
122
+ [
123
+ // add unique index(2025-03-28~)
124
+ { alternateName: 1 },
125
+ {
126
+ unique: true,
127
+ name: 'uniqueAlternateName',
128
+ partialFilterExpression: {
129
+ alternateName: { $exists: true }
130
+ }
131
+ }
132
+ ],
133
+ [
134
+ { identifier: 1 },
135
+ {
136
+ unique: true,
137
+ name: 'uniqueIdentifier',
138
+ partialFilterExpression: {
139
+ identifier: { $exists: true }
140
+ }
141
+ }
142
+ ]
143
+ ];
144
+ exports.indexes = indexes;
145
+ /**
146
+ * 非同期アクションスキーマ
147
+ */
148
+ let schema;
149
+ function createSchema() {
150
+ if (schema === undefined) {
151
+ schema = new mongoose_1.Schema(schemaDefinition, schemaOptions);
152
+ if (settings_1.MONGO_AUTO_INDEX) {
153
+ indexes.forEach((indexParams) => {
154
+ schema?.index(...indexParams);
155
+ });
156
+ }
157
+ }
158
+ return schema;
159
+ }
@@ -15,6 +15,7 @@ import type { CheckMovieTicketActionRepo } from './repo/action/checkMovieTicket'
15
15
  import type { CheckThingActionRepo } from './repo/action/checkThing';
16
16
  import type { PayActionRepo } from './repo/action/pay';
17
17
  import type { RefundActionRepo } from './repo/action/refund';
18
+ import type { AsyncActionRepo } from './repo/asyncAction';
18
19
  import type { AdditionalPropertyRepo } from './repo/additionalProperty';
19
20
  import type { AggregateActionRepo } from './repo/aggregateAction';
20
21
  import type { AggregateOfferRepo } from './repo/aggregateOffer';
@@ -470,6 +471,10 @@ export type Task = TaskRepo;
470
471
  export declare namespace Task {
471
472
  function createInstance(...params: ConstructorParameters<typeof TaskRepo>): Promise<TaskRepo>;
472
473
  }
474
+ export type AsyncAction = AsyncActionRepo;
475
+ export declare namespace AsyncAction {
476
+ function createInstance(...params: ConstructorParameters<typeof AsyncActionRepo>): Promise<AsyncActionRepo>;
477
+ }
473
478
  export type Ticket = TicketRepo;
474
479
  export declare namespace Ticket {
475
480
  function createInstance(...params: ConstructorParameters<typeof TicketRepo>): Promise<TicketRepo>;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.place = exports.Person = exports.PendingReservation = exports.PaymentServiceProvider = exports.PaymentServiceChannel = exports.PaymentService = exports.Passport = exports.OwnershipInfo = exports.OrderNumber = exports.OrderInTransaction = exports.Order = exports.Offer = exports.OfferItemCondition = exports.OfferCatalogItem = exports.OfferCatalog = exports.NoteAboutOrder = exports.Note = exports.MovieTicketType = exports.Message = exports.MerchantReturnPolicy = exports.MemberProgram = exports.Member = exports.Issuer = exports.IdentityProvider = exports.Identity = exports.EventSeries = exports.EventSellerMakesOffer = exports.EventOffer = exports.Event = exports.EmailMessage = exports.CustomerType = exports.Customer = exports.Credentials = exports.CreativeWork = exports.ConfirmationNumber = exports.Authorization = exports.CategoryCode = exports.assetTransaction = exports.AssetTransaction = exports.Aggregation = exports.AggregateReservation = exports.AggregateOrder = exports.AggregateOffer = exports.AggregateAction = exports.AdditionalProperty = exports.action = exports.Action = exports.AccountTitle = exports.AccountingReport = exports.AcceptedOffer = void 0;
4
- exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = void 0;
4
+ exports.WebSite = exports.rateLimit = exports.TransactionProcess = exports.TransactionNumber = exports.transaction = exports.Transaction = exports.Ticket = exports.AsyncAction = exports.Task = exports.StockHolder = exports.setting = exports.Setting = exports.ServiceAvailableHour = exports.SellerReturnPolicy = exports.SellerPaymentAccepted = exports.SellerMakesOffer = exports.Seller = exports.Schedule = exports.Role = exports.ReserveInterface = exports.Reservation = exports.ProjectMakesOffer = exports.Project = exports.ProductHasOfferCatalog = exports.Product = exports.PriceSpecification = exports.PotentialAction = void 0;
5
5
  var AcceptedOffer;
6
6
  (function (AcceptedOffer) {
7
7
  let repo;
@@ -989,6 +989,17 @@ var Task;
989
989
  }
990
990
  Task.createInstance = createInstance;
991
991
  })(Task || (exports.Task = Task = {}));
992
+ var AsyncAction;
993
+ (function (AsyncAction) {
994
+ let repo;
995
+ async function createInstance(...params) {
996
+ if (repo === undefined) {
997
+ repo = (await import('./repo/asyncAction.js')).AsyncActionRepo;
998
+ }
999
+ return new repo(...params);
1000
+ }
1001
+ AsyncAction.createInstance = createInstance;
1002
+ })(AsyncAction || (exports.AsyncAction = AsyncAction = {}));
992
1003
  var Ticket;
993
1004
  (function (Ticket) {
994
1005
  let repo;
@@ -1,7 +1,11 @@
1
- import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction, IReadyTask } from '../eventEmitter/task';
1
+ import type { IExecuteSettings as IMinimumExecuteSettings, INextFunction } from '../eventEmitter/task';
2
2
  type IExecuteSettings = IMinimumExecuteSettings;
3
3
  type IOperation<T> = (settings: IExecuteSettings) => Promise<T>;
4
- declare function executeAsyncActionById(params: IReadyTask & {
4
+ declare function executeAsyncActionById(params: {
5
+ /**
6
+ * タスクID
7
+ */
8
+ id: string;
5
9
  executor: {
6
10
  /**
7
11
  * タスク実行者名称
@@ -12,15 +12,13 @@ const asyncActionHandler_1 = require("./asyncActionHandler");
12
12
  const debug = (0, debug_1.default)('chevre-domain:service:task');
13
13
  function executeAsyncActionById(params, next) {
14
14
  return async (settings) => {
15
- const taskRepo = new (await import('../repo/task.js')).TaskRepo(settings.connection);
16
- const { id, status, executor, expires } = params;
15
+ const asyncActionRepo = new (await import('../repo/asyncAction.js')).AsyncActionRepo(settings.connection);
16
+ const { id, executor } = params;
17
17
  let task = null;
18
18
  try {
19
- task = await taskRepo.executeOneById({
19
+ task = await asyncActionRepo.executeAsyncActionById({
20
20
  id,
21
- status,
22
- executor: { name: executor.name },
23
- ...(expires instanceof Date) ? { expires } : undefined
21
+ executor: { name: executor.name }
24
22
  });
25
23
  }
26
24
  catch (error) {
@@ -1,19 +1,16 @@
1
- import type { IExecutedTask, INextFunction } from '../../eventEmitter/task';
2
- import { factory } from '../../factory';
1
+ import type { IExecutedTask } from '../../eventEmitter/task';
3
2
  import type { SettingRepo } from '../../repo/setting';
4
- import type { TaskRepo } from '../../repo/task';
5
- import type { IExecutableTask } from '../../taskSettings';
3
+ import type { AsyncActionRepo, IExecutableAsyncAction } from '../../repo/asyncAction';
6
4
  /**
7
5
  * タスク実行失敗時処理
8
6
  */
9
7
  declare function onOperationFailed(params: {
10
- task: IExecutableTask<factory.taskName>;
8
+ task: IExecutableAsyncAction;
11
9
  now: Date;
12
10
  error: any;
13
- next?: INextFunction;
14
11
  }): (repos: {
15
12
  setting: SettingRepo;
16
- task: TaskRepo;
13
+ asyncAction: AsyncActionRepo;
17
14
  }) => Promise<{
18
15
  executedTask: IExecutedTask;
19
16
  }>;
@@ -8,77 +8,35 @@ const factory_1 = require("../../factory");
8
8
  function onOperationFailed(params) {
9
9
  return async (repos) => {
10
10
  let error = params.error;
11
- const { task, now, next } = params;
11
+ const { task, now } = params;
12
12
  if (typeof error !== 'object') {
13
13
  error = { message: String(error) };
14
14
  }
15
15
  const endDate = new Date();
16
- let executedTask;
17
- // remainingNumberOfTries<=0ならAborted(2025-08-04~)
18
- const isRetryable = task.remainingNumberOfTries > 0;
19
- if (isRetryable) {
20
- // 実験的に実行中タスク連携をしてみたが、ひとまず廃止(2026-07-01~)
21
- // if (USE_INFORM_TASK_RUNNING) {
22
- // await informTaskIfNeeded({ task, executionEndDate: endDate })(repos);
23
- // }
24
- const result = {
25
- executedAt: now,
26
- endDate,
27
- error: {
28
- ...error,
29
- code: error.code,
30
- message: error.message,
31
- name: error.name,
32
- stack: error.stack
33
- }
34
- };
35
- // 失敗してもここではステータスを戻さない(Runningのまま待機)
36
- await repos.task.setExecutionResultAndStatus({
37
- id: task.id,
38
- remainingNumberOfTries: task.remainingNumberOfTries,
39
- name: task.name
40
- }, {
41
- status: task.status,
42
- executionResult: result
43
- }, (typeof next === 'function') ? next : undefined);
44
- executedTask = {
45
- id: task.id,
46
- remainingNumberOfTries: task.remainingNumberOfTries,
47
- name: task.name,
48
- status: task.status,
49
- executionResult: result
50
- };
51
- }
52
- else {
53
- // one time taskは分析連携しない
54
- // await informTaskIfNeeded({ task, executionEndDate: endDate })(repos);
55
- const result = {
56
- executedAt: now,
57
- endDate,
58
- error: {
59
- ...error,
60
- code: error.code,
61
- message: error.message,
62
- name: error.name,
63
- stack: error.stack
64
- }
65
- };
66
- await repos.task.setExecutionResultAndStatus({
67
- id: task.id,
68
- remainingNumberOfTries: task.remainingNumberOfTries,
69
- name: task.name
70
- }, {
71
- status: factory_1.factory.taskStatus.Aborted,
72
- executionResult: result
73
- }, (typeof next === 'function') ? next : undefined);
74
- executedTask = {
75
- id: task.id,
76
- remainingNumberOfTries: task.remainingNumberOfTries,
77
- name: task.name,
78
- status: task.status,
79
- executionResult: result
80
- };
81
- }
16
+ // 非同期アクションはワンタイムタスクなのでリトライはありえない
17
+ // ワンタイムタスクは分析連携しない
18
+ const result = {
19
+ executedAt: now,
20
+ endDate,
21
+ error: {
22
+ ...error,
23
+ code: error.code,
24
+ message: error.message,
25
+ name: error.name,
26
+ stack: error.stack
27
+ }
28
+ };
29
+ await repos.asyncAction.setExecutionResultAndStatus({ id: task.id }, {
30
+ status: factory_1.factory.taskStatus.Aborted,
31
+ executionResult: result
32
+ });
33
+ const executedTask = {
34
+ id: task.id,
35
+ remainingNumberOfTries: 0,
36
+ name: task.name,
37
+ status: task.status,
38
+ executionResult: result
39
+ };
82
40
  return { executedTask };
83
41
  };
84
42
  }
@@ -1,6 +1,6 @@
1
1
  import type { INextFunction } from '../eventEmitter/task';
2
- import { factory } from '../factory';
3
- import type { ICallResult, ICallableTaskOperation, IExecutableTask, IExecutableTaskKeys, IOperationExecute } from '../taskSettings';
2
+ import type { ICallResult, ICallableTaskOperation, IExecutableTaskKeys, IOperationExecute } from '../taskSettings';
3
+ import type { IExecutableAsyncAction } from '../repo/asyncAction';
4
4
  export declare const taskLoader: {
5
5
  load: (taskName: string) => Promise<{
6
6
  call: ICallableTaskOperation;
@@ -9,5 +9,5 @@ export declare const taskLoader: {
9
9
  /**
10
10
  * 非同期アクションを実行する
11
11
  */
12
- declare function executeAsyncAction(task: IExecutableTask<factory.taskName>, next?: INextFunction): IOperationExecute<void>;
12
+ declare function executeAsyncAction(task: IExecutableAsyncAction, next?: INextFunction): IOperationExecute<void>;
13
13
  export { ICallableTaskOperation, ICallResult, IExecutableTaskKeys, IOperationExecute, executeAsyncAction };
@@ -23,7 +23,7 @@ function executeAsyncAction(task, next) {
23
23
  debug('executing an executableTask...', task, now);
24
24
  return async (settings, options) => {
25
25
  const settingRepo = new (await import('../repo/setting.js')).SettingRepo(settings.connection);
26
- const taskRepo = new (await import('../repo/task.js')).TaskRepo(settings.connection);
26
+ const asyncActionRepo = new (await import('../repo/asyncAction.js')).AsyncActionRepo(settings.connection);
27
27
  let executedTask;
28
28
  try {
29
29
  // 期限検証(2024-04-23~)
@@ -34,16 +34,15 @@ function executeAsyncAction(task, next) {
34
34
  throw new factory_1.factory.errors.Internal(`task expired [expires:${task.expires}]`);
35
35
  }
36
36
  }
37
+ // remainingNumberOfTriesは存在しないので検証不要
37
38
  // remainingNumberOfTries<0ならcallを実行しない(2025-08-04~)
38
- // リトライを繰り返した後、不明の原因でRunningのまま残ってしまったタスクがリトライされたケース
39
- const { remainingNumberOfTries } = task;
40
- const isCallable = remainingNumberOfTries >= 0;
41
- if (!isCallable) {
42
- throw new factory_1.factory.errors.Internal(`task remainingNumberOfTries < 0 [remainingNumberOfTries:${remainingNumberOfTries}]`);
43
- }
44
39
  // タスク名の関数が定義されていなければ、TypeErrorとなる
45
40
  const { call } = await exports.taskLoader.load(task.name); // testが書きづらいのでtaskLoader経由で呼ぶ
46
- const callResult = await call(task)(settings, options);
41
+ const callResult = await call({
42
+ ...task,
43
+ numberOfTried: 1, // ひとまず固定でok(2026-07-26~)
44
+ remainingNumberOfTries: 0 // ひとまず固定でok(2026-07-26~)
45
+ })(settings, options);
47
46
  const result = {
48
47
  executedAt: now,
49
48
  endDate: new Date(),
@@ -55,11 +54,7 @@ function executeAsyncAction(task, next) {
55
54
  }
56
55
  : ''
57
56
  };
58
- await taskRepo.setExecutionResultAndStatus({
59
- id: task.id,
60
- remainingNumberOfTries,
61
- name: task.name
62
- }, {
57
+ await asyncActionRepo.setExecutionResultAndStatus({ id: task.id }, {
63
58
  status: factory_1.factory.taskStatus.Executed,
64
59
  executionResult: result
65
60
  });
@@ -74,8 +69,7 @@ function executeAsyncAction(task, next) {
74
69
  catch (error) {
75
70
  const onOperationFailedResult = await (0, onOperationFailed_1.onOperationFailed)({
76
71
  task, now, error,
77
- // ...(typeof next === 'function') ? { next } : undefined // タスクステータス変更イベントを発生させない
78
- })({ setting: settingRepo, task: taskRepo });
72
+ })({ setting: settingRepo, asyncAction: asyncActionRepo });
79
73
  executedTask = onOperationFailedResult.executedTask;
80
74
  }
81
75
  finally {
package/package.json CHANGED
@@ -88,5 +88,5 @@
88
88
  "postversion": "git push origin --tags",
89
89
  "prepublishOnly": "npm run clean && npm run build"
90
90
  },
91
- "version": "25.2.0-alpha.46"
91
+ "version": "25.2.0-alpha.48"
92
92
  }