@ravox-ui/cli 0.2.0 → 0.2.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.
- package/package.json +1 -1
- package/src/connect.mjs +7 -1
package/package.json
CHANGED
package/src/connect.mjs
CHANGED
|
@@ -13,6 +13,10 @@ import { servidorLocal } from "./local.mjs";
|
|
|
13
13
|
|
|
14
14
|
const CONFIG = join(homedir(), ".config", "ravox-ui", "conector.json");
|
|
15
15
|
const INTERVALO = 2000;
|
|
16
|
+
// Idle for a while (no request seen): ask every 10 s instead of 2 s, so a connector left open all day costs the site
|
|
17
|
+
// five times fewer calls. The site still sees it as connected (its heartbeat window is 60 s).
|
|
18
|
+
const INTERVALO_PARADO = 10000;
|
|
19
|
+
const PARADO_APOS = 3 * 60 * 1000;
|
|
16
20
|
const PROGRESSO = 1200;
|
|
17
21
|
|
|
18
22
|
const pt = /^pt/i.test(process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || Intl.DateTimeFormat().resolvedOptions().locale);
|
|
@@ -327,6 +331,7 @@ export async function conectar(opts) {
|
|
|
327
331
|
// resuming the session (a resumed one piles up every version of the code, costs more and trips the safety filter).
|
|
328
332
|
let parar = false;
|
|
329
333
|
let pausado = false;
|
|
334
|
+
let ativoEm = Date.now();
|
|
330
335
|
process.once("SIGINT", () => {
|
|
331
336
|
parar = true;
|
|
332
337
|
console.log("");
|
|
@@ -337,6 +342,7 @@ export async function conectar(opts) {
|
|
|
337
342
|
try {
|
|
338
343
|
for (const [tipo, listar, responder] of filas) {
|
|
339
344
|
const r = await chamar(site, token, listar, { conector: true });
|
|
345
|
+
if (r.pedidos?.some((x) => x.status === "pendente" || x.status === "fazendo")) ativoEm = Date.now();
|
|
340
346
|
if (!!r.pausado !== pausado) {
|
|
341
347
|
pausado = !!r.pausado;
|
|
342
348
|
console.log(pausado ? t.pausado : t.retomado);
|
|
@@ -378,7 +384,7 @@ export async function conectar(opts) {
|
|
|
378
384
|
console.log(t.falhaRede(e instanceof Error ? e.message : e));
|
|
379
385
|
await espera(INTERVALO * 3);
|
|
380
386
|
}
|
|
381
|
-
await espera(INTERVALO);
|
|
387
|
+
await espera(Date.now() - ativoEm > PARADO_APOS ? INTERVALO_PARADO : INTERVALO);
|
|
382
388
|
}
|
|
383
389
|
return 0;
|
|
384
390
|
}
|