MCPcopy Create free account
hub / github.com/angular/dev-infra / addUpstream

Method addUpstream

github-actions/browserstack/set-browserstack-env.js:8707–8733  ·  view source on GitHub ↗
(upstream)

Source from the content-addressed store, hash-verified

8705 this[kCurrentWeight] = 0;
8706 this[kMaxWeightPerServer] = this[kOptions].maxWeightPerServer || 100;
8707 this[kErrorPenalty] = this[kOptions].errorPenalty || 15;
8708 if (!Array.isArray(upstreams)) {
8709 upstreams = [upstreams];
8710 }
8711 if (typeof factory !== "function") {
8712 throw new InvalidArgumentError("factory must be a function.");
8713 }
8714 this[kInterceptors] = ((_a2 = opts.interceptors) == null ? void 0 : _a2.BalancedPool) && Array.isArray(opts.interceptors.BalancedPool) ? opts.interceptors.BalancedPool : [];
8715 this[kFactory] = factory;
8716 for (const upstream of upstreams) {
8717 this.addUpstream(upstream);
8718 }
8719 this._updateBalancedPoolStats();
8720 }
8721 addUpstream(upstream) {
8722 const upstreamOrigin = parseOrigin(upstream).origin;
8723 if (this[kClients].find((pool2) => pool2[kUrl].origin === upstreamOrigin && pool2.closed !== true && pool2.destroyed !== true)) {
8724 return this;
8725 }
8726 const pool = this[kFactory](upstreamOrigin, Object.assign({}, this[kOptions]));
8727 this[kAddClient](pool);
8728 pool.on("connect", () => {
8729 pool[kWeight] = Math.min(this[kMaxWeightPerServer], pool[kWeight] + this[kErrorPenalty]);
8730 });
8731 pool.on("connectionError", () => {
8732 pool[kWeight] = Math.max(1, pool[kWeight] - this[kErrorPenalty]);
8733 this._updateBalancedPoolStats();
8734 });
8735 pool.on("disconnect", (...args) => {
8736 const err = args[2];

Callers 1

constructorMethod · 0.45

Calls 3

parseOriginFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected