MCPcopy Index your code
hub / github.com/di-sukharev/opencommit / addUpstream

Method addUpstream

out/cli.cjs:55786–55812  ·  view source on GitHub ↗
(upstream)

Source from the content-addressed store, hash-verified

55784 }
55785 this[kInterceptors] = opts.interceptors && opts.interceptors.BalancedPool && Array.isArray(opts.interceptors.BalancedPool) ? opts.interceptors.BalancedPool : [];
55786 this[kFactory] = factory;
55787 for (const upstream of upstreams) {
55788 this.addUpstream(upstream);
55789 }
55790 this._updateBalancedPoolStats();
55791 }
55792 addUpstream(upstream) {
55793 const upstreamOrigin = parseOrigin(upstream).origin;
55794 if (this[kClients].find((pool2) => pool2[kUrl].origin === upstreamOrigin && pool2.closed !== true && pool2.destroyed !== true)) {
55795 return this;
55796 }
55797 const pool = this[kFactory](upstreamOrigin, Object.assign({}, this[kOptions]));
55798 this[kAddClient](pool);
55799 pool.on("connect", () => {
55800 pool[kWeight] = Math.min(this[kMaxWeightPerServer], pool[kWeight] + this[kErrorPenalty]);
55801 });
55802 pool.on("connectionError", () => {
55803 pool[kWeight] = Math.max(1, pool[kWeight] - this[kErrorPenalty]);
55804 this._updateBalancedPoolStats();
55805 });
55806 pool.on("disconnect", (...args) => {
55807 const err = args[2];
55808 if (err && err.code === "UND_ERR_SOCKET") {
55809 pool[kWeight] = Math.max(1, pool[kWeight] - this[kErrorPenalty]);
55810 this._updateBalancedPoolStats();
55811 }
55812 });
55813 for (const client of this[kClients]) {
55814 client[kWeight] = this[kMaxWeightPerServer];
55815 }

Callers 1

constructorMethod · 0.80

Calls 5

parseOriginFunction · 0.85
onMethod · 0.45
minMethod · 0.45
maxMethod · 0.45

Tested by

no test coverage detected