Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retry to put http #9480

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions scopes/harmony/express/express.main.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Server } from 'http';
import { Slot, SlotRegistry } from '@teambit/harmony';
import { Logger, LoggerAspect, LoggerMain } from '@teambit/logger';
import express, { Express } from 'express';
import { concat, flatten, lowerCase, sortBy } from 'lodash';
import { concat, flatten, lowerCase, sortBy, omit } from 'lodash';
import bodyParser from 'body-parser';
import { ExpressAspect } from './express.aspect';
import { catchErrors } from './middlewares';
Expand Down Expand Up @@ -94,7 +94,8 @@ export class ExpressMain {
const app = expressApp || express();
app.use((req, res, next) => {
if (this.config.loggerIgnorePath.includes(req.url)) return next();
this.logger.debug(`express got a request to a URL: ${req.url}', headers:`, req.headers);
const headers = omit(req.headers, ['cookie', 'authorization']);
this.logger.debug(`express got a request to a URL: ${req.url}', headers:`, headers);
return next();
});
if (!options?.disableBodyParser) this.bodyParser(app);
Expand Down
52 changes: 32 additions & 20 deletions scopes/scope/network/http/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,39 @@ export class Http implements Network {
errors: { [scopeName: string]: string };
metadata?: { jobs?: string[] };
}> {
const route = 'api/put';
logger.debug(`Http.pushToCentralHub, started. url: ${this.url}/${route}. total objects ${objectList.count()}`);
const pack = objectList.toTar();
const opts = this.addAgentIfExist({
method: 'post',
body: pack,
headers: this.getHeaders({ 'push-options': JSON.stringify(options), 'x-verb': Verb.WRITE }),
});
const res = await _fetch(`${this.url}/${route}`, opts);
logger.debug(
`Http.pushToCentralHub, completed. url: ${this.url}/${route}, status ${res.status} statusText ${res.statusText}`
);
const _data = await retry(
async () => {
const route = 'api/put';
logger.debug(`Http.pushToCentralHub, started. url: ${this.url}/${route}. total objects ${objectList.count()}`);
const pack = objectList.toTar();
const opts = this.addAgentIfExist({
method: 'post',
body: pack,
headers: this.getHeaders({ 'push-options': JSON.stringify(options), 'x-verb': Verb.WRITE }),
});
const res = await _fetch(`${this.url}/${route}`, opts);
logger.debug(
`Http.pushToCentralHub, completed. url: ${this.url}/${route}, status ${res.status} statusText ${res.statusText}`
);

// @ts-ignore TODO: need to fix this
const results = await this.readPutCentralStream(res.body);
if (!results.data) throw new Error(`HTTP results are missing "data" property`);
if (results.data.isError) {
throw new UnexpectedNetworkError(results.message);
}
await this.throwForNonOkStatus(res);
return results.data;
// @ts-ignore TODO: need to fix this
const results = await this.readPutCentralStream(res.body);
if (!results.data) throw new Error(`HTTP results are missing "data" property`);
if (results.data.isError) {
throw new UnexpectedNetworkError(results.message);
}
await this.throwForNonOkStatus(res);
return results.data;
},
{
retries: 3,
minTimeout: 5000,
onRetry: (e: any) => {
logger.debug(`failed to export with error: ${e?.message || ''}`);
},
}
);
return _data;
}

async deleteViaCentralHub(
Expand Down