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

feat: clean up proxy logging with n/N in each lookup #1839

Merged
merged 4 commits into from
Jan 31, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,25 @@ function buildSetupString(

function buildProductString(link: Link, store: Store, color?: boolean): string {
if (color) {
return (
chalk.cyan(`[${store.name}]`) +
chalk.grey(` [${link.brand} (${link.series})] ${link.model}`)
);
if (store.currentProxyIndex !== undefined && store.proxyList) {
const proxy = `${store.currentProxyIndex + 1}/${store.proxyList.length}`;
return (
chalk.gray(`[${proxy}]`) +
chalk.cyan(` [${store.name}]`) +
chalk.grey(` [${link.brand} (${link.series})] ${link.model}`)
);
} else {
return (
chalk.cyan(`[${store.name}]`) +
chalk.grey(` [${link.brand} (${link.series})] ${link.model}`)
);
}
}

return `[${store.name}] [${link.brand} (${link.series})] ${link.model}`;
if (store.currentProxyIndex !== undefined && store.proxyList) {
const proxy = `${store.currentProxyIndex + 1}/${store.proxyList.length}`;
return `[${proxy}] [${store.name}] [${link.brand} (${link.series})] ${link.model}`;
} else {
return `[${store.name}] [${link.brand} (${link.series})] ${link.model}`;
}
}
30 changes: 22 additions & 8 deletions src/store/lookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,18 @@ function nextProxy(store: Store) {

if (store.currentProxyIndex === undefined) {
store.currentProxyIndex = 0;
} else {
store.currentProxyIndex++;
}

store.currentProxyIndex++;
if (store.currentProxyIndex >= store.proxyList.length) {
store.currentProxyIndex = 0;
}

logger.info(
`ℹ [${store.name}] Next proxy index: ${store.currentProxyIndex} / Count: ${store.proxyList.length}`
logger.debug(
`ℹ [${store.name}] Next proxy index: ${store.currentProxyIndex} / Count: ${
store.proxyList.length
} (${store.proxyList[store.currentProxyIndex]})`
);

return store.proxyList[store.currentProxyIndex];
Expand Down Expand Up @@ -252,11 +255,22 @@ async function lookup(browser: Browser, store: Store) {
try {
statusCode = await lookupCard(browser, store, page, link);
} catch (error: unknown) {
logger.error(
`✖ [${store.name}] ${link.brand} ${link.series} ${link.model} - ${
(error as Error).message
}`
);
if (store.currentProxyIndex !== undefined && store.proxyList) {
const proxy = `${store.currentProxyIndex + 1}/${
store.proxyList.length
}`;
logger.error(
`✖ [${proxy}] [${store.name}] ${link.brand} ${link.series} ${
link.model
} - ${(error as Error).message}`
);
} else {
logger.error(
`✖ [${store.name}] ${link.brand} ${link.series} ${link.model} - ${
(error as Error).message
}`
);
}
const client = await page.target().createCDPSession();
await client.send('Network.clearBrowserCookies');
}
Expand Down