rewrite retry logic

This commit is contained in:
Henri Maurer
2023-06-08 18:11:13 +01:00
parent 1a326fc7fa
commit 1644401f8d
3 changed files with 54 additions and 57 deletions
Generated Vendored
+23 -29
View File
@@ -490,40 +490,34 @@ function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
});
}
function getComparison(baseRef, headRef, opts) {
return __awaiter(this, void 0, void 0, function* () {
const comparison = yield dependencyGraph.compare({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
baseRef,
headRef
});
if (comparison.snapshot_warnings.trim() !== '' && opts.retries > 0) {
core.info(comparison.snapshot_warnings);
core.info('Retrying in 10 seconds...');
yield delay(opts.retryDelay);
return getComparison(baseRef, headRef, Object.assign(Object.assign({}, opts), { retries: opts.retries - 1 }));
}
return comparison;
});
}
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
const config = yield (0, config_1.readConfig)();
const refs = (0, git_refs_1.getRefs)(config, github.context);
let changes;
let snapshot_warnings;
let i = 0;
while (true) {
const comparison = yield dependencyGraph.compare({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
baseRef: refs.base,
headRef: refs.head
});
if (i >= 12) {
core.info(comparison.snapshot_warnings);
core.info('Proceeding...');
changes = comparison.changes;
snapshot_warnings = comparison.snapshot_warnings;
break;
}
else if (comparison.snapshot_warnings.trim() !== '') {
core.info(comparison.snapshot_warnings);
core.info('Retrying in 10 seconds...');
yield delay(10000);
}
else {
changes = comparison.changes;
snapshot_warnings = comparison.snapshot_warnings;
break;
}
i++;
}
const comparison = yield getComparison(refs.base, refs.head, {
retries: 10,
retryDelay: 10000
});
const changes = comparison.changes;
const snapshot_warnings = comparison.snapshot_warnings;
if (!changes) {
core.info('No Dependency Changes found. Skipping Dependency Review.');
return;
Generated Vendored
+1 -1
View File
File diff suppressed because one or more lines are too long
+30 -27
View File
@@ -21,39 +21,42 @@ async function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms))
}
async function getComparison(
baseRef: string,
headRef: string,
opts: {
retries: number
retryDelay: number
}
): ReturnType<typeof dependencyGraph.compare> {
const comparison = await dependencyGraph.compare({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
baseRef,
headRef
})
if (comparison.snapshot_warnings.trim() !== '' && opts.retries > 0) {
core.info(comparison.snapshot_warnings)
core.info('Retrying in 10 seconds...')
await delay(opts.retryDelay)
return getComparison(baseRef, headRef, {...opts, retries: opts.retries - 1})
}
return comparison
}
async function run(): Promise<void> {
try {
const config = await readConfig()
const refs = getRefs(config, github.context)
let changes
let snapshot_warnings
let i = 0
while (true) {
const comparison = await dependencyGraph.compare({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
baseRef: refs.base,
headRef: refs.head
})
if (i >= 12) {
core.info(comparison.snapshot_warnings)
core.info('Proceeding...')
changes = comparison.changes
snapshot_warnings = comparison.snapshot_warnings
break
} else if (comparison.snapshot_warnings.trim() !== '') {
core.info(comparison.snapshot_warnings)
core.info('Retrying in 10 seconds...')
await delay(10000)
} else {
changes = comparison.changes
snapshot_warnings = comparison.snapshot_warnings
break
}
i++
}
const comparison = await getComparison(refs.base, refs.head, {
retries: 10,
retryDelay: 10_000
})
const changes = comparison.changes
const snapshot_warnings = comparison.snapshot_warnings
if (!changes) {
core.info('No Dependency Changes found. Skipping Dependency Review.')