@chevre/domain 22.11.0-alpha.36 → 22.11.0-alpha.37

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,89 @@
1
+ // tslint:disable:no-console no-magic-numbers
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
+ const delayInSeconds = 60;
10
+ const numExecuteByRequest = 50;
11
+ const selfName = 'sample';
12
+
13
+ const excludedTaskNames = [
14
+ chevre.factory.taskName.DeleteTransaction,
15
+ chevre.factory.taskName.ImportEventCapacitiesFromCOA,
16
+ chevre.factory.taskName.ImportEventsFromCOA,
17
+ chevre.factory.taskName.AcceptCOAOffer,
18
+ chevre.factory.taskName.CheckMovieTicket,
19
+ chevre.factory.taskName.AuthorizePayment,
20
+ chevre.factory.taskName.PublishPaymentUrl
21
+ ];
22
+
23
+ async function main() {
24
+ await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false, appName: 'sample' });
25
+
26
+ const now = new Date();
27
+ const runsAtLt = moment(now)
28
+ .add(-delayInSeconds, 'seconds')
29
+ .toDate();
30
+
31
+ let allTaskNames = Object.values(chevre.factory.taskName);
32
+ allTaskNames = allTaskNames.filter((name) => !excludedTaskNames.includes(name));
33
+ console.log('allTaskNames:', allTaskNames, allTaskNames.length);
34
+
35
+ const taskRepo = await chevre.repository.Task.createInstance(mongoose.connection);
36
+
37
+ const delayedTask: Pick<chevre.factory.task.ITask<chevre.factory.taskName>, 'id' | 'name'>[] = [];
38
+
39
+ // const { count } = await taskRepo.countPotentiallyRunning({
40
+ // name: { $in: allTaskNames },
41
+ // runsAt: { $lt: runsAtLt },
42
+ // limit: numExecuteByRequest
43
+ // });
44
+ // console.log('countPotentiallyRunning:', count);
45
+ // const executeCount: number = Math.min(count, numExecuteByRequest);
46
+ const executeCount: number = numExecuteByRequest;
47
+ const sort: {
48
+ numberOfTried?: chevre.factory.sortType;
49
+ runsAt?: chevre.factory.sortType;
50
+ } = {
51
+ numberOfTried: chevre.factory.sortType.Ascending, // numberOfTriedソートを加えるとどうなるのか?
52
+ runsAt: chevre.factory.sortType.Ascending
53
+ };
54
+
55
+ for (let i = 0; i < executeCount; i += 1) {
56
+ const runningTask = await taskRepo.emitRunningIfExists(
57
+ {
58
+ name: { $in: allTaskNames },
59
+ runsAt: { $lt: runsAtLt },
60
+ sort,
61
+ executor: {
62
+ name: selfName
63
+ },
64
+ nameFilterBeforeRunsAt: false
65
+ }
66
+ );
67
+ console.log('runningTask found', JSON.stringify(runningTask), i, now);
68
+ if (runningTask !== null) {
69
+ delayedTask.push(runningTask);
70
+ }
71
+ }
72
+ }
73
+
74
+ const interval = setInterval(
75
+ () => {
76
+ main()
77
+ .then()
78
+ .catch(console.error);
79
+ },
80
+ 1000
81
+ );
82
+
83
+ setTimeout(
84
+ () => {
85
+ clearInterval(interval);
86
+ console.log('interval cleared');
87
+ },
88
+ 600000
89
+ );
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.7",
15
- "@cinerino/sdk": "11.2.0-alpha.0",
14
+ "@chevre/factory": "4.396.0-alpha.8",
15
+ "@cinerino/sdk": "11.2.0-alpha.2",
16
16
  "@motionpicture/coa-service": "9.6.0",
17
17
  "@motionpicture/gmo-service": "5.3.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.36"
118
+ "version": "22.11.0-alpha.37"
119
119
  }