@resolveio/server-lib 1.1.0 → 1.1.1
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.
|
@@ -19,7 +19,6 @@ var method_response_collection_1 = require("../collections/method-response.colle
|
|
|
19
19
|
var mongoose_1 = require("mongoose");
|
|
20
20
|
var common_1 = require("../util/common");
|
|
21
21
|
var log_collection_1 = require("../collections/log.collection");
|
|
22
|
-
var cron_jobs_3 = require("../support-methods/cron-jobs");
|
|
23
22
|
var support_manager_1 = require("./support.manager");
|
|
24
23
|
var MethodManager = /** @class */ (function () {
|
|
25
24
|
function MethodManager(mainServer, serverConfig, clientDir) {
|
|
@@ -43,7 +42,6 @@ var MethodManager = /** @class */ (function () {
|
|
|
43
42
|
pdf_1.loadPDFMethods(this);
|
|
44
43
|
cron_jobs_2.loadCronJobMethods(this);
|
|
45
44
|
flags_1.loadFlagMethods(this);
|
|
46
|
-
cron_jobs_3.loadSupportCronJobMethods(this);
|
|
47
45
|
this._mailer = nodemailer.createTransport({
|
|
48
46
|
SES: new aws.SES({
|
|
49
47
|
apiVersion: '2010-12-01',
|
package/methods/cron-jobs.js
CHANGED
|
@@ -36,6 +36,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
var queue_method_collection_1 = require("../collections/queue-method.collection");
|
|
39
|
+
var user_collection_1 = require("../collections/user.collection");
|
|
40
|
+
var simpl_schema_1 = require("simpl-schema");
|
|
41
|
+
var mongoose_1 = require("mongoose");
|
|
39
42
|
function loadCronJobMethods(methodManager) {
|
|
40
43
|
methodManager.methods({
|
|
41
44
|
methodQueue: {
|
|
@@ -57,6 +60,58 @@ function loadCronJobMethods(methodManager) {
|
|
|
57
60
|
});
|
|
58
61
|
}); });
|
|
59
62
|
}
|
|
63
|
+
},
|
|
64
|
+
updateClientUsers: {
|
|
65
|
+
function: function () {
|
|
66
|
+
var _this = this;
|
|
67
|
+
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
68
|
+
var users, count, interval;
|
|
69
|
+
var _this = this;
|
|
70
|
+
return __generator(this, function (_a) {
|
|
71
|
+
switch (_a.label) {
|
|
72
|
+
case 0:
|
|
73
|
+
if (!user_collection_1.ClientUsers) {
|
|
74
|
+
resolve();
|
|
75
|
+
return [2 /*return*/];
|
|
76
|
+
}
|
|
77
|
+
return [4 /*yield*/, user_collection_1.Users.find({})];
|
|
78
|
+
case 1:
|
|
79
|
+
users = _a.sent();
|
|
80
|
+
count = 0;
|
|
81
|
+
interval = setInterval(function () {
|
|
82
|
+
var updateChunk = users.slice(count * 10, Math.min(users.length, (count + 1) * 10));
|
|
83
|
+
_this.callSupportMethodInternal.call(_this, 'updateClientUserChunk', updateChunk);
|
|
84
|
+
count++;
|
|
85
|
+
if (count * 10 > users.length) {
|
|
86
|
+
clearInterval(interval);
|
|
87
|
+
resolve(true);
|
|
88
|
+
}
|
|
89
|
+
}, 1000);
|
|
90
|
+
resolve();
|
|
91
|
+
return [2 /*return*/];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}); });
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
updateClientUserChunk: {
|
|
98
|
+
check: new simpl_schema_1.default({
|
|
99
|
+
users: {
|
|
100
|
+
type: Array
|
|
101
|
+
},
|
|
102
|
+
'users.$': {
|
|
103
|
+
type: Object,
|
|
104
|
+
blackbox: true
|
|
105
|
+
}
|
|
106
|
+
}),
|
|
107
|
+
function: function (users) {
|
|
108
|
+
return new Promise(function (resolve, reject) {
|
|
109
|
+
users.forEach(function (user) {
|
|
110
|
+
user_collection_1.ClientUsers.updateOne({ _id: user._id }, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: user }, { upsert: true }).exec();
|
|
111
|
+
});
|
|
112
|
+
resolve();
|
|
113
|
+
});
|
|
114
|
+
}
|
|
60
115
|
}
|
|
61
116
|
});
|
|
62
117
|
}
|
package/package.json
CHANGED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (_) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
var user_collection_1 = require("../collections/user.collection");
|
|
39
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
40
|
-
var mongoose_1 = require("mongoose");
|
|
41
|
-
function loadSupportCronJobMethods(methodManager) {
|
|
42
|
-
methodManager.methods({
|
|
43
|
-
updateClientUsers: {
|
|
44
|
-
function: function () {
|
|
45
|
-
var _this = this;
|
|
46
|
-
return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
47
|
-
var users, count, interval;
|
|
48
|
-
var _this = this;
|
|
49
|
-
return __generator(this, function (_a) {
|
|
50
|
-
switch (_a.label) {
|
|
51
|
-
case 0:
|
|
52
|
-
if (!user_collection_1.ClientUsers) {
|
|
53
|
-
resolve();
|
|
54
|
-
return [2 /*return*/];
|
|
55
|
-
}
|
|
56
|
-
return [4 /*yield*/, user_collection_1.Users.find({})];
|
|
57
|
-
case 1:
|
|
58
|
-
users = _a.sent();
|
|
59
|
-
count = 0;
|
|
60
|
-
interval = setInterval(function () {
|
|
61
|
-
var updateChunk = users.slice(count * 10, Math.min(users.length, (count + 1) * 10));
|
|
62
|
-
_this.callSupportMethodInternal.call(_this, 'updateClientUserChunk', updateChunk);
|
|
63
|
-
count++;
|
|
64
|
-
if (count * 10 > users.length) {
|
|
65
|
-
clearInterval(interval);
|
|
66
|
-
resolve(true);
|
|
67
|
-
}
|
|
68
|
-
}, 1000);
|
|
69
|
-
resolve();
|
|
70
|
-
return [2 /*return*/];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}); });
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
updateClientUserChunk: {
|
|
77
|
-
check: new simpl_schema_1.default({
|
|
78
|
-
users: {
|
|
79
|
-
type: Array
|
|
80
|
-
},
|
|
81
|
-
'users.$': {
|
|
82
|
-
type: Object,
|
|
83
|
-
blackbox: true
|
|
84
|
-
}
|
|
85
|
-
}),
|
|
86
|
-
function: function (users) {
|
|
87
|
-
return new Promise(function (resolve, reject) {
|
|
88
|
-
users.forEach(function (user) {
|
|
89
|
-
user_collection_1.ClientUsers.updateOne({ _id: user._id }, { $setOnInsert: { _id: mongoose_1.Types.ObjectId().toHexString(), __v: 0 }, $set: user }, { upsert: true }).exec();
|
|
90
|
-
});
|
|
91
|
-
resolve();
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
exports.loadSupportCronJobMethods = loadSupportCronJobMethods;
|