@engineering-tf/shared 1.0.1 → 1.0.2
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.
|
@@ -1,3 +1,17 @@
|
|
|
1
1
|
import { Webhook } from "discord-webhook-node";
|
|
2
|
+
export declare const localLogging: (msg: string) => void;
|
|
2
3
|
export declare const TRADINGFLOW_ALL_TEST_LOG: string;
|
|
3
4
|
export declare function discordMessageSender(msg: string, channel: Webhook): Promise<void>;
|
|
5
|
+
/**
|
|
6
|
+
* discord has a 2000 character limit, so we need to truncate the string
|
|
7
|
+
* @param input
|
|
8
|
+
* @param maxLength
|
|
9
|
+
* @param useEllipsis
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Wait for a random number of seconds (useful for retry backoff)
|
|
14
|
+
* @param maxSeconds Maximum seconds to wait
|
|
15
|
+
* @returns Promise that resolves after the random delay
|
|
16
|
+
*/
|
|
17
|
+
export declare function waitForRandomSecs(maxSeconds: number): Promise<void>;
|
|
@@ -36,12 +36,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.discordMessageSender = exports.TRADINGFLOW_ALL_TEST_LOG = void 0;
|
|
39
|
+
exports.waitForRandomSecs = exports.discordMessageSender = exports.TRADINGFLOW_ALL_TEST_LOG = exports.localLogging = void 0;
|
|
40
40
|
var localLogging = function (msg) {
|
|
41
41
|
if (process.env.NODE_ENV !== 'production' && process.env.CUSTOM_NODE_ENV !== 'production') {
|
|
42
42
|
console.log("[LOCAL ONLY LOG] ".concat(msg));
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
|
+
exports.localLogging = localLogging;
|
|
45
46
|
exports.TRADINGFLOW_ALL_TEST_LOG = "https://discord.com/api/webhooks/1024841963209490542/Pn45x2jJ4-jlXKF9V5mXMJtCNgD4LgOBW6daEBJOBz9WalSt7NsxXimJMi1RvOiRVvDW";
|
|
46
47
|
function discordMessageSender(msg, channel) {
|
|
47
48
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -49,7 +50,7 @@ function discordMessageSender(msg, channel) {
|
|
|
49
50
|
return __generator(this, function (_a) {
|
|
50
51
|
switch (_a.label) {
|
|
51
52
|
case 0:
|
|
52
|
-
localLogging("[LOCAL LOGGING] send message to discord: ".concat(msg, ")"));
|
|
53
|
+
(0, exports.localLogging)("[LOCAL LOGGING] send message to discord: ".concat(msg, ")"));
|
|
53
54
|
_a.label = 1;
|
|
54
55
|
case 1:
|
|
55
56
|
_a.trys.push([1, 3, , 4]);
|
|
@@ -62,7 +63,7 @@ function discordMessageSender(msg, channel) {
|
|
|
62
63
|
/**
|
|
63
64
|
* Sometime, we are not able to send discord messages
|
|
64
65
|
*/
|
|
65
|
-
localLogging("Not able to send discord message, err is ".concat(err_1.message, " ").concat(JSON.stringify(err_1)));
|
|
66
|
+
(0, exports.localLogging)("Not able to send discord message, err is ".concat(err_1.message, " ").concat(JSON.stringify(err_1)));
|
|
66
67
|
return [3 /*break*/, 4];
|
|
67
68
|
case 4: return [2 /*return*/];
|
|
68
69
|
}
|
|
@@ -77,6 +78,16 @@ exports.discordMessageSender = discordMessageSender;
|
|
|
77
78
|
* @param useEllipsis
|
|
78
79
|
* @returns
|
|
79
80
|
*/
|
|
81
|
+
/**
|
|
82
|
+
* Wait for a random number of seconds (useful for retry backoff)
|
|
83
|
+
* @param maxSeconds Maximum seconds to wait
|
|
84
|
+
* @returns Promise that resolves after the random delay
|
|
85
|
+
*/
|
|
86
|
+
function waitForRandomSecs(maxSeconds) {
|
|
87
|
+
var ms = Math.random() * maxSeconds * 1000;
|
|
88
|
+
return new Promise(function (resolve) { return setTimeout(resolve, ms); });
|
|
89
|
+
}
|
|
90
|
+
exports.waitForRandomSecs = waitForRandomSecs;
|
|
80
91
|
function truncateString(input, maxLength, useEllipsis) {
|
|
81
92
|
if (maxLength === void 0) { maxLength = 1990; }
|
|
82
93
|
if (useEllipsis === void 0) { useEllipsis = true; }
|