@chevre/domain 22.11.0-alpha.39 → 22.11.0-alpha.40

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.
@@ -5,7 +5,7 @@ import * as mongoose from 'mongoose';
5
5
  import { chevre } from '../../../../lib/index';
6
6
 
7
7
  // const TASK_STORAGE_PERIOD_IN_MINUTES = 43200; // 30*24*60
8
- const TASK_STORAGE_PERIOD_IN_MINUTES = 28800; // 20*24*60
8
+ const TASK_STORAGE_PERIOD_IN_MINUTES = 20160; // 14*24*60
9
9
 
10
10
  async function main() {
11
11
  const now = new Date();
@@ -13,7 +13,7 @@ async function main() {
13
13
 
14
14
  const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
15
15
 
16
- let taskInMinutes = 44640; // 31*24*60
16
+ let taskInMinutes = 21600; // 15*24*60
17
17
  // let taskInMinutes = 172800; // 120*24*60
18
18
  // tslint:disable-next-line:no-magic-numbers
19
19
  while (taskInMinutes > TASK_STORAGE_PERIOD_IN_MINUTES) {
@@ -1,20 +1,14 @@
1
1
  import type { Connection } from 'mongoose';
2
- import type { RedisClientType } from 'redis';
3
2
  import { AbstractStockHolderRepo, IGetHolderResult, ILockKey, IOffer, IUnlockKey } from './stockHolderAbstract';
4
3
  export { ILockKey, IOffer, IUnlockKey };
5
4
  /**
6
- * イベントストックホルダーリポジトリ
5
+ * 保留予約リポジトリ
7
6
  */
8
7
  export declare class StockHolderRepo implements AbstractStockHolderRepo {
9
- static KEY_PREFIX_NEW: string;
10
- private readonly redisClient;
11
8
  private readonly pendingReservationRepo;
12
9
  constructor(params: {
13
- redisClient?: RedisClientType;
14
10
  connection: Connection;
15
11
  });
16
- private static offer2field;
17
- private static createKey;
18
12
  /**
19
13
  * 座席をロックする(maxキャパシティチェック有)
20
14
  */
@@ -53,22 +47,6 @@ export declare class StockHolderRepo implements AbstractStockHolderRepo {
53
47
  hasTicketedSeat: boolean;
54
48
  offers: IOffer[];
55
49
  }): Promise<IGetHolderResult[]>;
56
- redisKeyExists(params: {
57
- eventId: string;
58
- startDate: Date;
59
- }): Promise<boolean>;
60
- /**
61
- * 万が一に備えて、保留予約をredis->mongo移行
62
- */
63
- migrate2mongoJustInCase(params: {
64
- eventId: string;
65
- startDate: Date;
66
- }): Promise<{
67
- expireTime: number;
68
- hash: {
69
- [x: string]: string;
70
- };
71
- }>;
72
50
  /**
73
51
  * 新リポジトリを使用するかどうか
74
52
  */
@@ -10,49 +10,47 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.StockHolderRepo = void 0;
13
- const createDebug = require("debug");
14
- const moment = require("moment");
13
+ // import type { RedisClientType } from 'redis';
15
14
  const factory = require("../factory");
16
15
  const pendingReservation_1 = require("./pendingReservation");
17
- const debug = createDebug('chevre-domain:repo:stockHolder');
18
16
  const SEARCH_OFFERS_MAX_LENGTH = 100;
19
17
  /**
20
- * イベントストックホルダーリポジトリ
18
+ * 保留予約リポジトリ
21
19
  */
22
20
  class StockHolderRepo {
23
21
  constructor(params) {
24
- const { redisClient, connection } = params;
25
- this.redisClient = redisClient;
22
+ const { connection } = params;
23
+ // this.redisClient = redisClient;
26
24
  this.pendingReservationRepo = new pendingReservation_1.PendingReservationRepo(connection);
27
25
  }
28
- static offer2field(params, hasTicketedSeat) {
29
- var _a, _b;
30
- if (hasTicketedSeat) {
31
- return `${params.seatSection}:${params.seatNumber}`;
32
- }
33
- else {
34
- // 予約IDをfieldにする場合
35
- const serviceOutputId = (_b = (_a = params.itemOffered) === null || _a === void 0 ? void 0 : _a.serviceOutput) === null || _b === void 0 ? void 0 : _b.id;
36
- if (typeof serviceOutputId === 'string') {
37
- return serviceOutputId;
38
- }
39
- else {
40
- throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
41
- }
42
- }
43
- }
44
- static createKey(params) {
45
- if (!(params.startDate instanceof Date)) {
46
- throw new factory.errors.Argument('startDate', 'must be Date');
47
- }
48
- return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
49
- }
26
+ // private static offer2field(params: IOffer, hasTicketedSeat: boolean) {
27
+ // if (hasTicketedSeat) {
28
+ // return `${params.seatSection}:${params.seatNumber}`;
29
+ // } else {
30
+ // // 予約IDをfieldにする場合
31
+ // const serviceOutputId = params.itemOffered?.serviceOutput?.id;
32
+ // if (typeof serviceOutputId === 'string') {
33
+ // return serviceOutputId;
34
+ // } else {
35
+ // throw new factory.errors.Internal('offer2field requires itemOffered.serviceOutput.id');
36
+ // }
37
+ // }
38
+ // }
39
+ // private static createKey(params: {
40
+ // eventId: string;
41
+ // startDate: Date;
42
+ // }): string {
43
+ // if (!(params.startDate instanceof Date)) {
44
+ // throw new factory.errors.Argument('startDate', 'must be Date');
45
+ // }
46
+ // return `${StockHolderRepo.KEY_PREFIX_NEW}:${params.eventId}`;
47
+ // }
50
48
  /**
51
49
  * 座席をロックする(maxキャパシティチェック有)
52
50
  */
53
51
  lockIfNotLimitExceeded(lockKey, maximum) {
54
52
  return __awaiter(this, void 0, void 0, function* () {
55
- const useMongoose = yield this.useMongoose({
53
+ const useMongoose = this.useMongoose({
56
54
  project: { id: lockKey.project.id },
57
55
  eventId: lockKey.eventId,
58
56
  startDate: lockKey.startDate,
@@ -62,17 +60,17 @@ class StockHolderRepo {
62
60
  return this.pendingReservationRepo.lockIfNotLimitExceeded(lockKey, maximum);
63
61
  }
64
62
  else {
65
- if (this.redisClient === undefined) {
66
- throw new factory.errors.Internal('redisClient required');
67
- }
68
- const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
69
- yield this.redisClient.watch(key);
70
- const hashCount = yield this.redisClient.hLen(key);
71
- debug('checking hash count...hashCount:', hashCount);
72
- if (hashCount + lockKey.offers.length > maximum) {
73
- throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
74
- }
75
- yield this.lock(lockKey);
63
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
64
+ // if (this.redisClient === undefined) {
65
+ // throw new factory.errors.Internal('redisClient required');
66
+ // }
67
+ // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
68
+ // await this.redisClient.watch(key);
69
+ // const hashCount = await this.redisClient.hLen(key);
70
+ // if (hashCount + lockKey.offers.length > maximum) {
71
+ // throw new factory.errors.Argument('Event', 'maximumAttendeeCapacity exceeded');
72
+ // }
73
+ // await this.lock(lockKey);
76
74
  }
77
75
  });
78
76
  }
@@ -85,64 +83,65 @@ class StockHolderRepo {
85
83
  if (!(lockKey.expires instanceof Date)) {
86
84
  throw new factory.errors.Argument('expires', 'must be Date');
87
85
  }
88
- const useMongoose = yield this.useMongoose({
86
+ const useMongoose = this.useMongoose({
89
87
  project: { id: lockKey.project.id },
90
88
  eventId: lockKey.eventId,
91
89
  startDate: lockKey.startDate,
92
90
  hasTicketedSeat: lockKey.hasTicketedSeat
93
91
  });
94
- const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
92
+ // const key = StockHolderRepo.createKey({ eventId: lockKey.eventId, startDate: lockKey.startDate });
95
93
  // await this.checkIfConflicted({ key, eventId: lockKey.eventId, useMongoose });
96
94
  if (useMongoose) {
97
95
  return this.pendingReservationRepo.lock(lockKey);
98
96
  }
99
97
  else {
100
- if (this.redisClient === undefined) {
101
- throw new factory.errors.Internal('redisClient required');
102
- }
103
- const value = lockKey.holder;
104
- const multi = this.redisClient.multi();
105
- const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
106
- // check uniqueness(2025-04-20~)
107
- const uniqueFields = [...new Set(fields)];
108
- if (uniqueFields.length !== fields.length) {
109
- throw new factory.errors.Argument('offers', 'offers must be unique');
110
- }
111
- fields.forEach((field) => {
112
- multi.hSetNX(key, field, value);
113
- });
114
- const results = yield multi.expireAt(key, moment(lockKey.expires)
115
- .unix())
116
- .exec();
117
- const lockedFields = [];
118
- if (Array.isArray(results)) {
119
- results.slice(0, fields.length)
120
- .forEach((r, index) => {
121
- if (r === 1 || r === true) {
122
- lockedFields.push(fields[index]);
123
- }
124
- });
125
- }
126
- const lockedAll = lockedFields.length === fields.length;
127
- debug('lockedAll?', lockedAll);
128
- // expireAtReplyの検証も追加する(2023-04-19~)
129
- const expiredAll = results.slice(fields.length)
130
- .every((r) => (r === 1 || r === true));
131
- debug('expiredAll?', expiredAll);
132
- if (!lockedAll || !expiredAll) {
133
- if (lockedFields.length > 0) {
134
- // 全て仮押さえできなければ仮押さえできたものは解除
135
- yield this.redisClient.multi()
136
- .hDel(key, lockedFields)
137
- .exec();
138
- }
139
- if (!lockedAll) {
140
- throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
141
- }
142
- else {
143
- throw new factory.errors.Internal('timeout cannot be set unexpectedly');
144
- }
145
- }
98
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
99
+ // if (this.redisClient === undefined) {
100
+ // throw new factory.errors.Internal('redisClient required');
101
+ // }
102
+ // const value = lockKey.holder;
103
+ // const multi = this.redisClient.multi();
104
+ // const fields = lockKey.offers.map((offer) => StockHolderRepo.offer2field(offer, lockKey.hasTicketedSeat));
105
+ // // check uniqueness(2025-04-20~)
106
+ // const uniqueFields = [...new Set(fields)];
107
+ // if (uniqueFields.length !== fields.length) {
108
+ // throw new factory.errors.Argument('offers', 'offers must be unique');
109
+ // }
110
+ // fields.forEach((field) => {
111
+ // multi.hSetNX(key, field, value);
112
+ // });
113
+ // const results = await multi.expireAt(
114
+ // key,
115
+ // moment(lockKey.expires)
116
+ // .unix()
117
+ // )
118
+ // .exec();
119
+ // const lockedFields: string[] = [];
120
+ // if (Array.isArray(results)) {
121
+ // results.slice(0, fields.length)
122
+ // .forEach((r, index) => {
123
+ // if (r === 1 || (<any>r) === true) {
124
+ // lockedFields.push(fields[index]);
125
+ // }
126
+ // });
127
+ // }
128
+ // const lockedAll = lockedFields.length === fields.length;
129
+ // // expireAtReplyの検証も追加する(2023-04-19~)
130
+ // const expiredAll = results.slice(fields.length)
131
+ // .every((r) => (r === 1 || (<any>r) === true));
132
+ // if (!lockedAll || !expiredAll) {
133
+ // if (lockedFields.length > 0) {
134
+ // // 全て仮押さえできなければ仮押さえできたものは解除
135
+ // await this.redisClient.multi()
136
+ // .hDel(key, lockedFields)
137
+ // .exec();
138
+ // }
139
+ // if (!lockedAll) {
140
+ // throw new factory.errors.AlreadyInUse(factory.reservationType.EventReservation, ['ticketedSeat'], 'Already hold');
141
+ // } else {
142
+ // throw new factory.errors.Internal('timeout cannot be set unexpectedly');
143
+ // }
144
+ // }
146
145
  }
147
146
  });
148
147
  }
@@ -151,25 +150,26 @@ class StockHolderRepo {
151
150
  */
152
151
  unlock(params) {
153
152
  return __awaiter(this, void 0, void 0, function* () {
154
- const useMongoose = yield this.useMongoose({
153
+ const useMongoose = this.useMongoose({
155
154
  project: { id: params.project.id },
156
155
  eventId: params.eventId,
157
156
  startDate: params.startDate,
158
157
  hasTicketedSeat: params.hasTicketedSeat
159
158
  });
160
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
159
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
161
160
  // await this.checkIfConflicted({ key, eventId: params.eventId, useMongoose });
162
161
  if (useMongoose) {
163
162
  return this.pendingReservationRepo.unlock(params);
164
163
  }
165
164
  else {
166
- if (this.redisClient === undefined) {
167
- throw new factory.errors.Internal('redisClient required');
168
- }
169
- const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
170
- yield this.redisClient.multi()
171
- .hDel(key, field)
172
- .exec();
165
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
166
+ // if (this.redisClient === undefined) {
167
+ // throw new factory.errors.Internal('redisClient required');
168
+ // }
169
+ // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
170
+ // await this.redisClient.multi()
171
+ // .hDel(key, field)
172
+ // .exec();
173
173
  }
174
174
  });
175
175
  }
@@ -178,7 +178,7 @@ class StockHolderRepo {
178
178
  */
179
179
  countUnavailableOffers(params) {
180
180
  return __awaiter(this, void 0, void 0, function* () {
181
- if (yield this.useMongoose({
181
+ if (this.useMongoose({
182
182
  project: { id: params.project.id },
183
183
  eventId: params.event.id,
184
184
  startDate: params.event.startDate,
@@ -187,16 +187,17 @@ class StockHolderRepo {
187
187
  return this.pendingReservationRepo.countUnavailableOffers(params);
188
188
  }
189
189
  else {
190
- if (this.redisClient === undefined) {
191
- throw new factory.errors.Internal('redisClient required');
192
- }
193
- const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
194
- const reply = yield this.redisClient.hLen(key);
195
- let fieldCount = 0;
196
- if (typeof reply === 'number') {
197
- fieldCount = Number(reply);
198
- }
199
- return fieldCount;
190
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
191
+ // if (this.redisClient === undefined) {
192
+ // throw new factory.errors.Internal('redisClient required');
193
+ // }
194
+ // const key = StockHolderRepo.createKey({ eventId: params.event.id, startDate: params.event.startDate });
195
+ // const reply = await this.redisClient.hLen(key);
196
+ // let fieldCount: number = 0;
197
+ // if (typeof reply === 'number') {
198
+ // fieldCount = Number(reply);
199
+ // }
200
+ // return fieldCount;
200
201
  }
201
202
  });
202
203
  }
@@ -205,7 +206,7 @@ class StockHolderRepo {
205
206
  */
206
207
  getHolder(params) {
207
208
  return __awaiter(this, void 0, void 0, function* () {
208
- if (yield this.useMongoose({
209
+ if (this.useMongoose({
209
210
  project: { id: params.project.id },
210
211
  eventId: params.eventId,
211
212
  startDate: params.startDate,
@@ -214,12 +215,13 @@ class StockHolderRepo {
214
215
  return this.pendingReservationRepo.getHolder(params);
215
216
  }
216
217
  else {
217
- if (this.redisClient === undefined) {
218
- throw new factory.errors.Internal('redisClient required');
219
- }
220
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
221
- const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
222
- return this.redisClient.hGet(key, field);
218
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
219
+ // if (this.redisClient === undefined) {
220
+ // throw new factory.errors.Internal('redisClient required');
221
+ // }
222
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
223
+ // const field = StockHolderRepo.offer2field(params.offer, params.hasTicketedSeat);
224
+ // return this.redisClient.hGet(key, field);
223
225
  }
224
226
  });
225
227
  }
@@ -229,7 +231,7 @@ class StockHolderRepo {
229
231
  if (params.offers.length > SEARCH_OFFERS_MAX_LENGTH) {
230
232
  throw new factory.errors.Argument('offers', `offers.length must be <= ${SEARCH_OFFERS_MAX_LENGTH}`);
231
233
  }
232
- if (yield this.useMongoose({
234
+ if (this.useMongoose({
233
235
  project: { id: params.project.id },
234
236
  eventId: params.eventId,
235
237
  startDate: params.startDate,
@@ -238,36 +240,24 @@ class StockHolderRepo {
238
240
  return this.pendingReservationRepo.searchHolders(params);
239
241
  }
240
242
  else {
241
- if (this.redisClient === undefined) {
242
- throw new factory.errors.Internal('redisClient required');
243
- }
244
- const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
245
- const fields = params.offers.map((o) => {
246
- return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
247
- });
248
- // Array reply: list of values associated with the given fields, in the same order as they are requested.
249
- const result = yield this.redisClient.hmGet(key, fields);
250
- if (!Array.isArray(result)) {
251
- throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
252
- }
253
- // そのまま返却(2023-04-17~)
254
- return result;
243
+ throw new factory.errors.NotImplemented('useRedis discontinued.');
244
+ // if (this.redisClient === undefined) {
245
+ // throw new factory.errors.Internal('redisClient required');
246
+ // }
247
+ // const key = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
248
+ // const fields = params.offers.map((o) => {
249
+ // return StockHolderRepo.offer2field(o, params.hasTicketedSeat);
250
+ // });
251
+ // // Array reply: list of values associated with the given fields, in the same order as they are requested.
252
+ // const result = await this.redisClient.hmGet(key, fields);
253
+ // if (!Array.isArray(result)) {
254
+ // throw new factory.errors.Internal(`searchAvailability got non-array: ${typeof result}`);
255
+ // }
256
+ // // そのまま返却(2023-04-17~)
257
+ // return result;
255
258
  }
256
259
  });
257
260
  }
258
- redisKeyExists(params) {
259
- return __awaiter(this, void 0, void 0, function* () {
260
- if (this.redisClient === undefined) {
261
- throw new factory.errors.Internal('redisClient required');
262
- }
263
- const key = StockHolderRepo.createKey(params);
264
- const existingRedisKeyCount = yield this.redisClient.exists(key);
265
- if (typeof existingRedisKeyCount !== 'number') {
266
- throw new factory.errors.Internal(`unexpected existingKeyCount: ${typeof existingRedisKeyCount}`);
267
- }
268
- return existingRedisKeyCount > 0;
269
- });
270
- }
271
261
  // public async checkIfConflicted(params: {
272
262
  // eventId: string;
273
263
  // startDate: Date;
@@ -278,47 +268,29 @@ class StockHolderRepo {
278
268
  // throw new factory.errors.Internal(`repository conflicted. eventId:${params.eventId}`);
279
269
  // }
280
270
  // }
281
- /**
282
- * 万が一に備えて、保留予約をredis->mongo移行
283
- */
284
- migrate2mongoJustInCase(params) {
285
- return __awaiter(this, void 0, void 0, function* () {
286
- if (this.redisClient === undefined) {
287
- throw new factory.errors.Internal('redisClient required');
288
- }
289
- const redisKey = StockHolderRepo.createKey({ eventId: params.eventId, startDate: params.startDate });
290
- return {
291
- expireTime: yield this.redisClient.expireTime(redisKey),
292
- hash: yield this.redisClient.hGetAll(redisKey)
293
- };
294
- });
295
- }
296
271
  /**
297
272
  * 新リポジトリを使用するかどうか
298
273
  */
299
274
  // tslint:disable-next-line:prefer-function-over-method
300
275
  useMongoose(params) {
301
- return __awaiter(this, void 0, void 0, function* () {
302
- if (!(params.startDate instanceof Date)) {
303
- throw new factory.errors.Argument('startDate', 'must be Date');
304
- }
305
- // always use mongo(2025-08-17~)
306
- return true;
307
- // let useMongoose = false;
308
- // const redisKeyExists = await this.redisKeyExists(params);
309
- // if (redisKeyExists) {
310
- // useMongoose = false;
311
- // } else {
312
- // // redis keyが存在しなければmongo利用
313
- // useMongoose = true;
314
- // }
315
- // // check confliction for test
316
- // if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
317
- // await this.checkIfConflicted(params);
318
- // }
319
- // return useMongoose;
320
- });
276
+ if (!(params.startDate instanceof Date)) {
277
+ throw new factory.errors.Argument('startDate', 'must be Date');
278
+ }
279
+ // always use mongo(2025-08-17~)
280
+ return true;
281
+ // let useMongoose = false;
282
+ // const redisKeyExists = await this.redisKeyExists(params);
283
+ // if (redisKeyExists) {
284
+ // useMongoose = false;
285
+ // } else {
286
+ // // redis keyが存在しなければmongo利用
287
+ // useMongoose = true;
288
+ // }
289
+ // // check confliction for test
290
+ // if (USE_STOCK_HOLDER_CHECK_CONFLICT) {
291
+ // await this.checkIfConflicted(params);
292
+ // }
293
+ // return useMongoose;
321
294
  }
322
295
  }
323
296
  exports.StockHolderRepo = StockHolderRepo;
324
- StockHolderRepo.KEY_PREFIX_NEW = 'stockHolder';
@@ -32,7 +32,7 @@ function call(data) {
32
32
  yield (0, aggregateOffers_1.aggregateOffers)(data)({
33
33
  aggregateReservation: new aggregateReservation_1.AggregateReservationRepo(connection),
34
34
  event: new event_1.EventRepo(connection),
35
- stockHolder: new stockHolder_1.StockHolderRepo({ redisClient, connection }),
35
+ stockHolder: new stockHolder_1.StockHolderRepo({ connection }),
36
36
  offer: new unitPriceInCatalog_1.OfferRepo(connection),
37
37
  offerCatalog: new offerCatalog_1.OfferCatalogRepo(connection),
38
38
  offerRateLimit: new offer_1.OfferRateLimitRepo(redisClient),
@@ -32,7 +32,7 @@ function call(data) {
32
32
  }
33
33
  yield AggregationService.event.aggregateScreeningEvent(data)({
34
34
  event: new event_1.EventRepo(connection),
35
- stockHolder: new stockHolder_1.StockHolderRepo({ redisClient, connection }),
35
+ stockHolder: new stockHolder_1.StockHolderRepo({ connection }),
36
36
  offer: new unitPriceInCatalog_1.OfferRepo(connection),
37
37
  offerCatalog: new offerCatalog_1.OfferCatalogRepo(connection),
38
38
  offerRateLimit: new offer_1.OfferRateLimitRepo(redisClient),
@@ -43,7 +43,7 @@ function call(params) {
43
43
  yield (0, cancelReservation_1.cancelPendingReservation)({ purpose: data.purpose })({
44
44
  action: new action_1.ActionRepo(connection),
45
45
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
46
- stockHolder: new stockHolder_1.StockHolderRepo({ redisClient, connection }),
46
+ stockHolder: new stockHolder_1.StockHolderRepo({ connection }),
47
47
  offerRateLimit: new offer_1.OfferRateLimitRepo(redisClient),
48
48
  reservation: new reservation_1.ReservationRepo(connection),
49
49
  setting: new setting_1.SettingRepo(connection),
@@ -34,7 +34,7 @@ function call(data) {
34
34
  task: new task_1.TaskRepo(connection),
35
35
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
36
36
  offerRateLimit: new offer_1.OfferRateLimitRepo(redisClient),
37
- stockHolder: new stockHolder_1.StockHolderRepo({ redisClient, connection })
37
+ stockHolder: new stockHolder_1.StockHolderRepo({ connection })
38
38
  }
39
39
  // settings
40
40
  );
@@ -59,7 +59,7 @@ function call(data) {
59
59
  project: { id: data.project.id }
60
60
  })({
61
61
  event: new event_1.EventRepo(connection),
62
- stockHolder: new stockHolder_1.StockHolderRepo({ redisClient, connection })
62
+ stockHolder: new stockHolder_1.StockHolderRepo({ connection })
63
63
  });
64
64
  break;
65
65
  default:
@@ -64,7 +64,7 @@ function call(params) {
64
64
  yield (0, voidTransaction_1.voidTransaction)(Object.assign(Object.assign({}, params.data), { project: { id: params.project.id }, sameAs: { id: params.id } }))({
65
65
  action: new action_1.ActionRepo(connection),
66
66
  assetTransaction: new assetTransaction_1.AssetTransactionRepo(connection),
67
- stockHolder: new stockHolder_1.StockHolderRepo({ redisClient, connection }),
67
+ stockHolder: new stockHolder_1.StockHolderRepo({ connection }),
68
68
  offerRateLimit: new offer_1.OfferRateLimitRepo(redisClient),
69
69
  orderInTransaction: new orderInTransaction_1.OrderInTransactionRepo(connection),
70
70
  reservation: new reservation_1.ReservationRepo(connection),
package/package.json CHANGED
@@ -11,8 +11,8 @@
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.9",
15
- "@cinerino/sdk": "11.2.0-alpha.2",
14
+ "@chevre/factory": "4.396.0",
15
+ "@cinerino/sdk": "12.0.0-alpha.0",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.4.0-alpha.0",
18
18
  "@sendgrid/client": "8.1.4",
@@ -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.39"
118
+ "version": "22.11.0-alpha.40"
119
119
  }
@@ -1,186 +0,0 @@
1
- // tslint:disable:no-console no-magic-numbers
2
- import * as moment from 'moment';
3
- import * as mongoose from 'mongoose';
4
- import * as redis from 'redis';
5
- import * as util from 'util';
6
-
7
- import { chevre } from '../../../../lib/index';
8
-
9
- // const project = { id: String(process.env.PROJECT_ID) };
10
- const { BACKLOG_ISSUE_KEY, BACKLOG_API_KEY, BACKLOG_SPACE_KEY } = process.env;
11
- const BACKLOG_NOTIFY_URL = `https://${BACKLOG_SPACE_KEY}.backlog.jp/api/v2/issues/${BACKLOG_ISSUE_KEY}/comments?apiKey=${BACKLOG_API_KEY}`;
12
-
13
- const client = redis.createClient<redis.RedisDefaultModules, Record<string, never>, Record<string, never>>({
14
- socket: {
15
- port: Number(<string>process.env.REDIS_PORT),
16
- host: <string>process.env.REDIS_HOST
17
- },
18
- password: <string>process.env.REDIS_KEY,
19
- name: 'checkRedisKeyCount'
20
- })
21
- .on('error', (err) => {
22
- // eslint-disable-next-line no-console
23
- console.error('createDefaultRedisClient: client onError:', err);
24
- // reject(err);
25
- });
26
- client.connect();
27
- mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
28
-
29
- function countRedisKeyByProject(params: {
30
- project: { id: string };
31
- now: Date;
32
- }) {
33
- return async (repos: {
34
- event: chevre.repository.Event;
35
- stockHolder: chevre.repository.StockHolder;
36
- }) => {
37
- const cursor = repos.event.getCursor(
38
- {
39
- 'project.id': {
40
- $eq: params.project.id
41
- },
42
- // startDate: {
43
- // $gte: params.now
44
- // },
45
- endDate: {
46
- $gte: params.now
47
- },
48
- typeOf: { $eq: chevre.factory.eventType.ScreeningEvent }
49
- // _id: { $eq: 'blyk9q24f' }
50
- },
51
- {
52
- _id: 1,
53
- // offers: 1,
54
- startDate: 1,
55
- project: 1,
56
- typeOf: 1
57
- }
58
- );
59
- console.log('events found');
60
-
61
- let i = 0;
62
- let redisKeyCount = 0;
63
- const eventsWithRedis: string[] = [];
64
- await cursor.eachAsync(async (doc) => {
65
- i += 1;
66
- const event: Pick<
67
- chevre.factory.event.screeningEvent.IEvent,
68
- 'id' | 'startDate' | 'project' | 'typeOf'
69
- > = doc.toObject();
70
-
71
- console.log('redisKeyExists?', event.project.id, event.typeOf, event.id, event.startDate, i);
72
- const redisKeyExists = await repos.stockHolder.redisKeyExists({
73
- eventId: event.id,
74
- startDate: event.startDate
75
- });
76
- console.log('redisKeyExists:', redisKeyExists, event.project.id, event.typeOf, event.id, event.startDate, i);
77
-
78
- if (redisKeyExists) {
79
- redisKeyCount += 1;
80
- eventsWithRedis.push(event.id);
81
- }
82
- });
83
-
84
- console.log(i, 'events checked');
85
- console.log(redisKeyCount, 'redisKeys found');
86
-
87
- return { checkedCount: i, redisKeyCount, eventsWithRedis };
88
- };
89
- }
90
-
91
- // tslint:disable-next-line:max-func-body-length
92
- async function main() {
93
- const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
94
- const projectRepo = await chevre.repository.Project.createInstance(mongoose.connection);
95
- // const settingRepo = await chevre.repository.Setting.createInstance(mongoose.connection);
96
- const stockHolderRepo = await chevre.repository.StockHolder.createInstance({
97
- redisClient: client,
98
- connection: mongoose.connection
99
- });
100
-
101
- let checkingProjects: string[] = [];
102
- // 全プロジェクト
103
- checkingProjects = (await projectRepo.projectFields(
104
- {
105
- // id: { $eq: 'xxx' }
106
- },
107
- ['id']
108
- )).map(({ id }) => id);
109
-
110
- checkingProjects = checkingProjects.filter((id) => id.slice(0, 6) !== 'sskts-');
111
-
112
- const results: {
113
- project: { id: string };
114
- checkedCount: number;
115
- redisKeyCount: number;
116
- }[] = [];
117
-
118
- const now = moment()
119
- .add(0, 'days')
120
- .toDate();
121
- for (const projectId of checkingProjects) {
122
- const { checkedCount, redisKeyCount } = await countRedisKeyByProject({
123
- project: { id: projectId },
124
- now
125
- })({
126
- event: eventRepo,
127
- stockHolder: stockHolderRepo
128
- });
129
- results.push({
130
- project: { id: projectId },
131
- checkedCount,
132
- redisKeyCount
133
- });
134
- // console.log(eventsWithRedis);
135
- }
136
-
137
- const header = util.format(
138
- '| %s | %s | %s | %s |\n| %s | %s | %s | %s |',
139
- `project `.slice(0, 40),
140
- `now `.slice(0, 24),
141
- `checkedCount `.slice(0, 24),
142
- `redisKeyCount `.slice(0, 24),
143
- `---------------------------------------- `.slice(0, 40),
144
- `------------------------ `.slice(0, 24),
145
- `------------------------ `.slice(0, 24),
146
- `------------------------ `.slice(0, 24)
147
- );
148
-
149
- const text = util.format(
150
- '%s\n%s',
151
- header,
152
- results.map((result) => {
153
- return util.format(
154
- '| %s | %s | %s | %s |',
155
- `${result.project.id} `.slice(0, 40),
156
- `${now.toISOString()} `.slice(0, 24),
157
- `${result.checkedCount} `.slice(0, 24),
158
- `${result.redisKeyCount} `.slice(0, 24)
159
- );
160
- })
161
- .join('\n')
162
- );
163
- console.log(text);
164
-
165
- // backlogへ通知
166
- if (typeof BACKLOG_API_KEY === 'string') {
167
- console.log('notifying on backlog...');
168
- await fetch(
169
- BACKLOG_NOTIFY_URL,
170
- {
171
- method: 'POST',
172
- headers: new Headers({ 'Content-Type': 'application/json' }),
173
- body: JSON.stringify({
174
- content: text,
175
- notifiedUserId: []
176
- // notifiedUserId: users.map((user) => user.id)
177
- })
178
- }
179
- );
180
- console.log('posted to backlog.');
181
- }
182
- }
183
-
184
- main()
185
- .then()
186
- .catch(console.error);