initial delay regbot (#80)

* initial delay regbot

* fix review comment

* fix review comment
This commit is contained in:
Hoan Luu Huu
2025-03-10 19:26:43 +07:00
committed by GitHub
parent 0f63223c55
commit e865286a2b
3 changed files with 11 additions and 2 deletions

View File

@@ -30,6 +30,7 @@ const JAMBONES_CLUSTER_ID = process.env.JAMBONES_CLUSTER_ID ;
const JAMBONES_REGBOT_CONTACT_USE_IP = process.env.JAMBONES_REGBOT_CONTACT_USE_IP;
const JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL = process.env.JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL;
const JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL = process.env.JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL;
const JAMBONES_REGBOT_INITIAL_DELAY_MS = process.env.JAMBONES_REGBOT_INITIAL_DELAY_MS || 250;
module.exports = {
JAMBONES_MYSQL_HOST,
@@ -55,5 +56,6 @@ module.exports = {
JAMBONES_CLUSTER_ID,
JAMBONES_REGBOT_CONTACT_USE_IP,
JAMBONES_REGBOT_MIN_EXPIRES_INTERVAL,
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL
JAMBONES_REGBOT_DEFAULT_EXPIRES_INTERVAL,
JAMBONES_REGBOT_INITIAL_DELAY_MS
};

View File

@@ -1,9 +1,11 @@
const debug = require('debug')('jambonz:sbc-registrar');
const {
JAMBONES_CLUSTER_ID,
JAMBONES_REGBOT_INITIAL_DELAY_MS,
} = require('./config');
const short = require('short-uuid');
const Regbot = require('./regbot');
const { sleepFor } = require('./utils');
const MAX_INITIAL_DELAY = 15;
const REGBOT_STATUS_CHECK_INTERVAL = 60;
@@ -185,6 +187,8 @@ const updateCarrierRegbots = async(logger, srf) => {
use_public_ip_in_contact: gw.carrier.register_public_ip_in_contact
});
regbots.push(rb);
// stagger the start of the regbots
await sleepFor(JAMBONES_REGBOT_INITIAL_DELAY_MS);
rb.start(srf);
} catch (err) {
const { updateVoipCarriersRegisterStatus } = srf.locals.dbHelpers;

View File

@@ -52,11 +52,14 @@ function isValidDomainOrIP(input) {
return false; // Invalid input
}
const sleepFor = async(ms) => new Promise((resolve) => setTimeout(resolve, ms));
module.exports = {
isUacBehindNat,
getSipProtocol,
addSipGatewayToBlacklist,
NAT_EXPIRES: 30,
isValidIPv4,
isValidDomainOrIP
isValidDomainOrIP,
sleepFor
};