@wikicasa-dev/node-common 2.5.0 → 3.0.0
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,25 +1,47 @@
|
|
|
1
1
|
import { CallPool, PROXY } from "../src/CallPool.js";
|
|
2
2
|
import { Console, COLORS } from "../src/Console.js";
|
|
3
3
|
async function demoCallPool() {
|
|
4
|
-
const pool = new CallPool(
|
|
4
|
+
const pool = new CallPool({
|
|
5
|
+
name: "demo",
|
|
6
|
+
proxy: PROXY.NONE,
|
|
7
|
+
minConcurrency: 1,
|
|
8
|
+
maxConcurrency: 100,
|
|
9
|
+
limitCall: 30,
|
|
10
|
+
limitInterval: 60000,
|
|
11
|
+
retry: {
|
|
12
|
+
attempts: 1,
|
|
13
|
+
delayMs: 2000,
|
|
14
|
+
shouldRetry: (error) => {
|
|
15
|
+
// Simuliamo che alcuni errori sono recuperabili e altri no
|
|
16
|
+
return error.message.includes("RETRY");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
});
|
|
5
20
|
Console.appendSummaryLine(() => pool.print(), COLORS.YELLOW, "pool_status");
|
|
6
|
-
// Funzione che simula una chiamata API con timeout casuale
|
|
21
|
+
// Funzione che simula una chiamata API con timeout casuale e diversi tipi di errori
|
|
7
22
|
const simulateApiCall = (id) => {
|
|
8
23
|
return new Promise((resolve, reject) => {
|
|
9
24
|
const delay = Math.random() * 4000 + 1100; // Ritardo casuale tra 1-5 secondi
|
|
10
|
-
const
|
|
25
|
+
const scenario = Math.random();
|
|
11
26
|
setTimeout(() => {
|
|
12
|
-
if (
|
|
13
|
-
resolve(`✨ Operazione ${id} completata in ${(delay / 1000).toFixed(1)}s`);
|
|
27
|
+
if (scenario > 0.000001) {
|
|
28
|
+
resolve(`✨ Operazione ${id} completata con successo in ${(delay / 1000).toFixed(1)}s`);
|
|
29
|
+
}
|
|
30
|
+
else if (scenario > 0.2) {
|
|
31
|
+
// Errore recuperabile (con RETRY nel messaggio)
|
|
32
|
+
reject(new Error(`RETRY: Errore temporaneo per operazione ${id} dopo ${(delay / 1000).toFixed(1)}s`));
|
|
14
33
|
}
|
|
15
34
|
else {
|
|
16
|
-
|
|
35
|
+
// Errore non recuperabile
|
|
36
|
+
reject(new Error(`FATAL: Errore permanente per operazione ${id} dopo ${(delay / 1000).toFixed(1)}s`));
|
|
17
37
|
}
|
|
18
38
|
}, delay);
|
|
19
39
|
});
|
|
20
40
|
};
|
|
21
|
-
// Creiamo
|
|
22
|
-
const operations = Array.from({ length:
|
|
41
|
+
// Creiamo 50 operazioni simulate
|
|
42
|
+
const operations = Array.from({ length: 50 }, (_, i) => i + 1);
|
|
43
|
+
Console.log("\n🚀 Avvio operazioni batch con retry...");
|
|
44
|
+
const time = performance.now();
|
|
23
45
|
// Aggiungiamo le operazioni al pool usando enqueue
|
|
24
46
|
const promises = operations.map(id => {
|
|
25
47
|
return pool.enqueue(() => simulateApiCall(id))
|
|
@@ -28,18 +50,32 @@ async function demoCallPool() {
|
|
|
28
50
|
return result;
|
|
29
51
|
})
|
|
30
52
|
.catch(error => {
|
|
31
|
-
|
|
53
|
+
const retryInfo = error.message.includes("RETRY") ?
|
|
54
|
+
" (dopo tutti i tentativi di retry)" :
|
|
55
|
+
" (errore non recuperabile)";
|
|
56
|
+
Console.error(`💥 ${error.message}${retryInfo}`);
|
|
32
57
|
throw error;
|
|
33
58
|
});
|
|
34
59
|
});
|
|
35
60
|
try {
|
|
36
61
|
await Promise.allSettled(promises);
|
|
37
62
|
Console.success("\n🎉 Demo completata! Tutte le operazioni sono state processate.");
|
|
63
|
+
// Stampiamo alcune statistiche
|
|
64
|
+
const results = await Promise.allSettled(promises);
|
|
65
|
+
const succeeded = results.filter(r => r.status === "fulfilled").length;
|
|
66
|
+
const failed = results.filter(r => r.status === "rejected").length;
|
|
67
|
+
Console.log("\n📊 Statistiche finali:");
|
|
68
|
+
Console.log(`🕒 Tempo di esecuzione: ${((performance.now() - time) / 1000).toFixed(1)}s`);
|
|
69
|
+
Console.log(`✅ Operazioni riuscite: ${succeeded}`);
|
|
70
|
+
Console.log(`❌ Operazioni fallite: ${failed}`);
|
|
71
|
+
Console.log(`📈 Chiamate al minuto: ${await pool.getActualCallsPerMinute()}`);
|
|
72
|
+
Console.log(`🔄 Chiamate totali: ${pool.getTotalCalls()}`);
|
|
38
73
|
}
|
|
39
74
|
catch (error) {
|
|
40
75
|
Console.error("Errore generale nella demo:", error);
|
|
41
76
|
}
|
|
42
77
|
finally {
|
|
78
|
+
await pool.finish(); // Aspettiamo che tutte le operazioni siano completate
|
|
43
79
|
Console.clearSummaryLines();
|
|
44
80
|
}
|
|
45
81
|
}
|
|
@@ -47,5 +83,9 @@ async function demoCallPool() {
|
|
|
47
83
|
Console.log("🚀 Avvio demo CallPool...\n");
|
|
48
84
|
demoCallPool().catch(error => {
|
|
49
85
|
Console.error("Errore fatale nella demo:", error);
|
|
86
|
+
})
|
|
87
|
+
.finally(() => {
|
|
88
|
+
Console.clearSummaryLines();
|
|
89
|
+
process.exit(0);
|
|
50
90
|
});
|
|
51
91
|
//# sourceMappingURL=callpool-demo.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"callpool-demo.js","sourceRoot":"","sources":["../../examples/callpool-demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEpD,KAAK,UAAU,YAAY;IACvB,MAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,EAAE,
|
|
1
|
+
{"version":3,"file":"callpool-demo.js","sourceRoot":"","sources":["../../examples/callpool-demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,OAAO,E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ED,kBAAkB;AAClB,OAAO,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;AAC3C,YAAY,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACzB,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;AACtD,CAAC,CAAC;KACG,OAAO,CAAC,GAAG,EAAE;IACV,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAC5B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
package/dist/src/CallPool.d.ts
CHANGED
|
@@ -4,14 +4,24 @@ export declare enum PROXY {
|
|
|
4
4
|
STATIC = 1,
|
|
5
5
|
DYNAMIC = 2
|
|
6
6
|
}
|
|
7
|
+
interface RetryConfig {
|
|
8
|
+
attempts: number;
|
|
9
|
+
shouldRetry?: (error: any) => boolean;
|
|
10
|
+
delayMs?: number;
|
|
11
|
+
}
|
|
12
|
+
interface CallPoolConfig {
|
|
13
|
+
name?: string;
|
|
14
|
+
proxy?: PROXY;
|
|
15
|
+
minConcurrency?: number;
|
|
16
|
+
maxConcurrency: number;
|
|
17
|
+
limitCall?: number;
|
|
18
|
+
limitInterval?: number;
|
|
19
|
+
retry?: Partial<RetryConfig>;
|
|
20
|
+
}
|
|
7
21
|
export declare class CallPool {
|
|
8
|
-
private name;
|
|
9
22
|
private concurrency;
|
|
10
|
-
private readonly minConcurrency;
|
|
11
|
-
private readonly maxConcurrency;
|
|
12
23
|
private _print;
|
|
13
24
|
private readonly limiter;
|
|
14
|
-
private readonly proxy;
|
|
15
25
|
private readonly CLOCK_NUMBER;
|
|
16
26
|
private readonly WEIGHT;
|
|
17
27
|
private mean;
|
|
@@ -20,18 +30,24 @@ export declare class CallPool {
|
|
|
20
30
|
private queue;
|
|
21
31
|
private activeCount;
|
|
22
32
|
private agent;
|
|
23
|
-
private
|
|
33
|
+
private callStack;
|
|
34
|
+
private callStackMutex;
|
|
35
|
+
private totalCalls;
|
|
24
36
|
private readonly MINUTE_IN_MS;
|
|
25
|
-
|
|
37
|
+
private readonly config;
|
|
38
|
+
private isScheduling;
|
|
39
|
+
constructor(config: CallPoolConfig);
|
|
26
40
|
private buildAxiosConfig;
|
|
41
|
+
private updateCallStack;
|
|
42
|
+
private executeLimited;
|
|
27
43
|
directCall(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse>;
|
|
28
44
|
call(url: string, config?: AxiosRequestConfig): Promise<AxiosResponse>;
|
|
29
45
|
private getRandomUserAgent;
|
|
30
46
|
enqueue(call: () => Promise<any>): Promise<any>;
|
|
31
47
|
private schedule;
|
|
48
|
+
private updateMetrics;
|
|
32
49
|
print(): string;
|
|
33
|
-
updatePrint(): void
|
|
34
|
-
private fetchWithRetry;
|
|
50
|
+
updatePrint(): Promise<void>;
|
|
35
51
|
/**
|
|
36
52
|
* Restituisce il numero di chiamate attualmente in coda
|
|
37
53
|
* @returns {number} Il numero di chiamate in coda
|
|
@@ -43,5 +59,7 @@ export declare class CallPool {
|
|
|
43
59
|
* @returns Promise che si risolve quando la coda è vuota e non ci sono chiamate attive
|
|
44
60
|
*/
|
|
45
61
|
finish(checkInterval?: number): Promise<void>;
|
|
46
|
-
getActualCallsPerMinute(): number
|
|
62
|
+
getActualCallsPerMinute(): Promise<number>;
|
|
63
|
+
getTotalCalls(): number;
|
|
47
64
|
}
|
|
65
|
+
export {};
|
package/dist/src/CallPool.js
CHANGED
|
@@ -8,31 +8,45 @@ import Agent from "agentkeepalive";
|
|
|
8
8
|
import * as RandomUserAgent from "random-useragent";
|
|
9
9
|
import _ from "lodash";
|
|
10
10
|
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
11
|
+
import { setImmediate } from "timers";
|
|
12
|
+
import { Mutex } from "async-mutex";
|
|
11
13
|
const cacheable = new CacheableLookup();
|
|
12
14
|
// Increase the limit
|
|
13
15
|
EventEmitter.defaultMaxListeners = 20;
|
|
14
16
|
//const a = new CallPool("test", 1, 10, 50, 1000, PROXY.DYNAMIC);
|
|
15
|
-
/*axiosRetry(axios, {
|
|
16
|
-
retries: 1,
|
|
17
|
-
retryDelay: (retryCount, error) => {
|
|
18
|
-
Console.log(`retry attempt: ${retryCount}. Error ${error}`);
|
|
19
|
-
return retryCount * 1000;
|
|
20
|
-
},
|
|
21
|
-
});*/
|
|
22
17
|
export var PROXY;
|
|
23
18
|
(function (PROXY) {
|
|
24
19
|
PROXY[PROXY["NONE"] = 0] = "NONE";
|
|
25
20
|
PROXY[PROXY["STATIC"] = 1] = "STATIC";
|
|
26
21
|
PROXY[PROXY["DYNAMIC"] = 2] = "DYNAMIC";
|
|
27
22
|
})(PROXY || (PROXY = {}));
|
|
23
|
+
const defaultRetryConfig = {
|
|
24
|
+
attempts: 1,
|
|
25
|
+
delayMs: 1000,
|
|
26
|
+
shouldRetry: (error) => {
|
|
27
|
+
if (!error.response)
|
|
28
|
+
return true; // errori di rete
|
|
29
|
+
const status = error.response.status;
|
|
30
|
+
// Retry per errori di server e alcuni errori client specifici
|
|
31
|
+
return (status >= 500 ||
|
|
32
|
+
status === 429 || // Too Many Requests
|
|
33
|
+
status === 408 // Request Timeout
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const defaultConfig = {
|
|
38
|
+
name: "default",
|
|
39
|
+
proxy: PROXY.NONE,
|
|
40
|
+
minConcurrency: 1,
|
|
41
|
+
maxConcurrency: 10,
|
|
42
|
+
limitCall: undefined,
|
|
43
|
+
limitInterval: undefined,
|
|
44
|
+
retry: defaultRetryConfig,
|
|
45
|
+
};
|
|
28
46
|
export class CallPool {
|
|
29
|
-
name;
|
|
30
47
|
concurrency;
|
|
31
|
-
minConcurrency = 1;
|
|
32
|
-
maxConcurrency;
|
|
33
48
|
_print = "";
|
|
34
49
|
limiter;
|
|
35
|
-
proxy;
|
|
36
50
|
CLOCK_NUMBER = 1;
|
|
37
51
|
WEIGHT = 100;
|
|
38
52
|
mean = 0;
|
|
@@ -42,18 +56,18 @@ export class CallPool {
|
|
|
42
56
|
activeCount;
|
|
43
57
|
// @ts-ignore
|
|
44
58
|
agent;
|
|
45
|
-
|
|
59
|
+
callStack = [];
|
|
60
|
+
callStackMutex = new Mutex();
|
|
61
|
+
totalCalls = 0;
|
|
46
62
|
MINUTE_IN_MS = 60000;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
this.
|
|
51
|
-
this.
|
|
63
|
+
config;
|
|
64
|
+
isScheduling = false;
|
|
65
|
+
constructor(config) {
|
|
66
|
+
this.config = { ...defaultConfig, ...config };
|
|
67
|
+
this.concurrency = (this.config.minConcurrency + this.config.maxConcurrency) / 2;
|
|
52
68
|
this.queue = [];
|
|
53
69
|
this.activeCount = 0;
|
|
54
|
-
|
|
55
|
-
this.limiter = throttledQueue(limitCall, limitInterval, true);
|
|
56
|
-
this.proxy = proxy;
|
|
70
|
+
this.limiter = throttledQueue(this.config.limitCall, this.config.limitInterval, true);
|
|
57
71
|
this.updatePrint();
|
|
58
72
|
this.agent = new Agent({
|
|
59
73
|
maxSockets: 100,
|
|
@@ -61,23 +75,11 @@ export class CallPool {
|
|
|
61
75
|
timeout: 30000,
|
|
62
76
|
lookup: cacheable.lookupAsync,
|
|
63
77
|
});
|
|
64
|
-
/*axios("https://api.ipify.org?format=json", {
|
|
65
|
-
method: "GET",
|
|
66
|
-
proxy: null,
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
fetch("https://api.ipify.org?format=json", {
|
|
70
|
-
method: "GET",
|
|
71
|
-
agent: null,
|
|
72
|
-
headers: {
|
|
73
|
-
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
|
|
74
|
-
}
|
|
75
|
-
})*/
|
|
76
78
|
}
|
|
77
79
|
buildAxiosConfig(config) {
|
|
78
80
|
return _.merge({
|
|
79
81
|
method: "GET",
|
|
80
|
-
proxy: this.proxy === PROXY.DYNAMIC ? {
|
|
82
|
+
proxy: this.config.proxy === PROXY.DYNAMIC ? {
|
|
81
83
|
protocol: "http",
|
|
82
84
|
host: "api.zyte.com",
|
|
83
85
|
port: 8011,
|
|
@@ -86,26 +88,59 @@ export class CallPool {
|
|
|
86
88
|
password: ""
|
|
87
89
|
},
|
|
88
90
|
} : undefined,
|
|
89
|
-
httpsAgent: this.proxy === PROXY.STATIC ? new HttpsProxyAgent("http://wikicasa:VTt7KYb5fsqDhK6xXinS@162.19.104.35:3128") : undefined,
|
|
90
|
-
httpAgent: this.proxy === PROXY.STATIC ? new HttpsProxyAgent("http://wikicasa:VTt7KYb5fsqDhK6xXinS@162.19.104.35:3128") : undefined,
|
|
91
|
+
httpsAgent: this.config.proxy === PROXY.STATIC ? new HttpsProxyAgent("http://wikicasa:VTt7KYb5fsqDhK6xXinS@162.19.104.35:3128") : undefined,
|
|
92
|
+
httpAgent: this.config.proxy === PROXY.STATIC ? new HttpsProxyAgent("http://wikicasa:VTt7KYb5fsqDhK6xXinS@162.19.104.35:3128") : undefined,
|
|
91
93
|
maxContentLength: Infinity,
|
|
92
94
|
maxBodyLength: Infinity,
|
|
93
95
|
timeout: 600000,
|
|
94
96
|
headers: {
|
|
95
|
-
...(this.proxy === PROXY.DYNAMIC && { "Zyte-Geolocation": "IT" }),
|
|
96
|
-
"User-Agent": this.proxy !== PROXY.NONE ? this.getRandomUserAgent() : undefined,
|
|
97
|
+
...(this.config.proxy === PROXY.DYNAMIC && { "Zyte-Geolocation": "IT" }),
|
|
98
|
+
"User-Agent": this.config.proxy !== PROXY.NONE ? this.getRandomUserAgent() : undefined,
|
|
97
99
|
}
|
|
98
100
|
}, config);
|
|
99
101
|
}
|
|
102
|
+
async updateCallStack() {
|
|
103
|
+
await this.callStackMutex.runExclusive(() => {
|
|
104
|
+
this.totalCalls++;
|
|
105
|
+
const now = Date.now();
|
|
106
|
+
this.callStack.push(now);
|
|
107
|
+
const oneMinuteAgo = now - this.MINUTE_IN_MS;
|
|
108
|
+
this.callStack = this.callStack.filter(timestamp => timestamp > oneMinuteAgo);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
executeLimited(call, resolve, reject, remainingAttempts = this.config.retry?.attempts) {
|
|
112
|
+
const time = performance.now();
|
|
113
|
+
this.activeCount++;
|
|
114
|
+
this.limiter(async () => {
|
|
115
|
+
try {
|
|
116
|
+
await this.updateCallStack();
|
|
117
|
+
const result = await call();
|
|
118
|
+
resolve(result);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (this.config.retry?.shouldRetry?.(error) && remainingAttempts > 0) {
|
|
122
|
+
Console.log(`${this.config.name}: Rimetto in coda il tentativo. Tentativi rimasti: ${remainingAttempts - 1}`);
|
|
123
|
+
await sleep(this.config.retry.delayMs);
|
|
124
|
+
this.executeLimited(call, resolve, reject, remainingAttempts - 1);
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
reject(error);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
finally {
|
|
131
|
+
this.activeCount--;
|
|
132
|
+
this.updateMetrics(time);
|
|
133
|
+
setImmediate(() => this.schedule());
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
100
137
|
async directCall(url, config) {
|
|
101
138
|
return axios(url, this.buildAxiosConfig(config));
|
|
102
139
|
}
|
|
103
140
|
call(url, config) {
|
|
104
141
|
return new Promise((resolve, reject) => {
|
|
105
142
|
this.queue.push({
|
|
106
|
-
call:
|
|
107
|
-
return axios(url, this.buildAxiosConfig(config));
|
|
108
|
-
},
|
|
143
|
+
call: () => axios(url, this.buildAxiosConfig(config)),
|
|
109
144
|
resolve,
|
|
110
145
|
reject
|
|
111
146
|
});
|
|
@@ -133,49 +168,45 @@ export class CallPool {
|
|
|
133
168
|
});
|
|
134
169
|
}
|
|
135
170
|
schedule() {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
call
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
})
|
|
151
|
-
.finally(() => {
|
|
152
|
-
this.completedCalls.push(Date.now());
|
|
153
|
-
const oneMinuteAgo = Date.now() - this.MINUTE_IN_MS;
|
|
154
|
-
this.completedCalls = this.completedCalls.filter(timestamp => timestamp > oneMinuteAgo);
|
|
155
|
-
this.activeCount--;
|
|
156
|
-
this.clock--;
|
|
157
|
-
if (this.clock < 0) {
|
|
158
|
-
this.clock = this.CLOCK_NUMBER;
|
|
159
|
-
if (this.mean > this.targetMean && this.mean > 10)
|
|
160
|
-
this.concurrency = Math.max(this.concurrency - Math.floor(this.concurrency / 10), this.minConcurrency);
|
|
161
|
-
if (this.mean < this.targetMean || this.mean < 2)
|
|
162
|
-
this.concurrency = Math.min(this.concurrency + Math.ceil(this.concurrency / 20), this.maxConcurrency);
|
|
163
|
-
this.targetMean = this.mean;
|
|
164
|
-
}
|
|
165
|
-
const t = (performance.now() - time) / 1000;
|
|
166
|
-
this.mean = this.mean > 0 ? this.mean + (t - this.mean) / this.WEIGHT : t;
|
|
167
|
-
this.updatePrint();
|
|
168
|
-
this.schedule();
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
+
if (this.isScheduling)
|
|
172
|
+
return;
|
|
173
|
+
this.isScheduling = true;
|
|
174
|
+
try {
|
|
175
|
+
while (this.activeCount < this.concurrency && this.queue.length > 0) {
|
|
176
|
+
const item = this.queue.shift();
|
|
177
|
+
if (!item)
|
|
178
|
+
break;
|
|
179
|
+
const { call, resolve, reject } = item;
|
|
180
|
+
this.executeLimited(call, resolve, reject);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
finally {
|
|
184
|
+
this.isScheduling = false;
|
|
171
185
|
}
|
|
172
186
|
}
|
|
187
|
+
updateMetrics(startTime) {
|
|
188
|
+
this.clock--;
|
|
189
|
+
if (this.clock < 0) {
|
|
190
|
+
this.clock = this.CLOCK_NUMBER;
|
|
191
|
+
if (this.mean > this.targetMean && this.mean > 10) {
|
|
192
|
+
this.concurrency = Math.max(this.concurrency - Math.floor(this.concurrency / 10), this.config.minConcurrency);
|
|
193
|
+
}
|
|
194
|
+
if (this.mean < this.targetMean || this.mean < 2) {
|
|
195
|
+
this.concurrency = Math.min(this.concurrency + Math.ceil(this.concurrency / 20), this.config.maxConcurrency);
|
|
196
|
+
}
|
|
197
|
+
this.targetMean = this.mean;
|
|
198
|
+
}
|
|
199
|
+
const t = (performance.now() - startTime) / 1000;
|
|
200
|
+
this.mean = this.mean > 0 ? this.mean + (t - this.mean) / this.WEIGHT : t;
|
|
201
|
+
this.updatePrint();
|
|
202
|
+
}
|
|
173
203
|
print() {
|
|
174
204
|
return this._print;
|
|
175
205
|
}
|
|
176
|
-
updatePrint() {
|
|
177
|
-
const textStart = `${Console.color(this.name.padEnd(16), COLORS.YELLOW)} [POOL][`;
|
|
178
|
-
const
|
|
206
|
+
async updatePrint() {
|
|
207
|
+
const textStart = `${Console.color(this.config.name.padEnd(16), COLORS.YELLOW)} [POOL][`;
|
|
208
|
+
const callsPerMinute = await this.getActualCallsPerMinute();
|
|
209
|
+
const textEnd = `][${this.activeCount + this.queue?.length}/${this.concurrency}][${this.mean.toFixed(2)}s, ${callsPerMinute} avg/m]`;
|
|
179
210
|
let progress = "";
|
|
180
211
|
const max = process.stdout.columns - Math.max(textStart.length + textEnd.length, process.stdout.columns * 0.5);
|
|
181
212
|
const percent = this.activeCount / this.concurrency * max;
|
|
@@ -186,21 +217,6 @@ export class CallPool {
|
|
|
186
217
|
this._print = textStart + progress + textEnd;
|
|
187
218
|
Console.forceSummaryLinesRefresh();
|
|
188
219
|
}
|
|
189
|
-
async fetchWithRetry(url, options, retries = 3, sleepTime = 1000) {
|
|
190
|
-
try {
|
|
191
|
-
const response = await fetch(url, options);
|
|
192
|
-
if (!response.ok)
|
|
193
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
194
|
-
return response;
|
|
195
|
-
}
|
|
196
|
-
catch (error) {
|
|
197
|
-
if (retries === 0)
|
|
198
|
-
throw new Error(`Failed to fetch ${url} after several retries`);
|
|
199
|
-
Console.log(`Retrying fetch for ${url}. Attempts remaining: ${retries - 1}`);
|
|
200
|
-
await sleep(sleepTime);
|
|
201
|
-
return this.fetchWithRetry(url, options, retries - 1);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
220
|
/**
|
|
205
221
|
* Restituisce il numero di chiamate attualmente in coda
|
|
206
222
|
* @returns {number} Il numero di chiamate in coda
|
|
@@ -218,9 +234,14 @@ export class CallPool {
|
|
|
218
234
|
await sleep(checkInterval);
|
|
219
235
|
}
|
|
220
236
|
}
|
|
221
|
-
getActualCallsPerMinute() {
|
|
222
|
-
|
|
223
|
-
|
|
237
|
+
async getActualCallsPerMinute() {
|
|
238
|
+
return await this.callStackMutex.runExclusive(() => {
|
|
239
|
+
const oneMinuteAgo = Date.now() - this.MINUTE_IN_MS;
|
|
240
|
+
return this.callStack.filter(timestamp => timestamp > oneMinuteAgo).length;
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
getTotalCalls() {
|
|
244
|
+
return this.totalCalls;
|
|
224
245
|
}
|
|
225
246
|
}
|
|
226
247
|
//# sourceMappingURL=CallPool.js.map
|
package/dist/src/CallPool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CallPool.js","sourceRoot":"","sources":["../../src/CallPool.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,
|
|
1
|
+
{"version":3,"file":"CallPool.js","sourceRoot":"","sources":["../../src/CallPool.ts"],"names":[],"mappings":"AAAA,OAAO,cAAc,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,MAAM,OA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C;IACL,CAAC;IAEM,KAAK,CAAC,uBAAuB;QAChC,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,GAAG,EAAE;YAC/C,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,YAAY,CAAC;YACpD,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,SAAS,GAAG,YAAY,CAAC,CAAC,MAAM,CAAC;QAC/E,CAAC,CAAC,CAAC;IACP,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACJ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wikicasa-dev/node-common",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Wikicasa node common",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"@elastic/elasticsearch": "^8.15.0",
|
|
23
23
|
"@supercharge/promise-pool": "^3.2.0",
|
|
24
24
|
"agentkeepalive": "^4.5.0",
|
|
25
|
+
"async-mutex": "^0.5.0",
|
|
25
26
|
"axios": "^1.7.7",
|
|
26
27
|
"axios-retry": "^4.5.0",
|
|
27
28
|
"cacheable-lookup": "^7.0.0",
|