fix: improve ping performance (#1020)
This commit is contained in:
@@ -15,18 +15,20 @@ export const pingJob = createCronJob("ping", EVERY_MINUTE, {
|
|||||||
}).withCallback(async () => {
|
}).withCallback(async () => {
|
||||||
const urls = await pingUrlChannel.getAllAsync();
|
const urls = await pingUrlChannel.getAllAsync();
|
||||||
|
|
||||||
for (const url of new Set(urls)) {
|
await Promise.allSettled([...new Set(urls)].map(pingAsync));
|
||||||
const pingResult = await sendPingRequestAsync(url);
|
|
||||||
|
|
||||||
if ("statusCode" in pingResult) {
|
|
||||||
logger.debug(`executed ping for url ${url} with status code ${pingResult.statusCode}`);
|
|
||||||
} else {
|
|
||||||
logger.error(`Executing ping for url ${url} failed with error: ${pingResult.error}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await pingChannel.publishAsync({
|
|
||||||
url,
|
|
||||||
...pingResult,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pingAsync = async (url: string) => {
|
||||||
|
const pingResult = await sendPingRequestAsync(url);
|
||||||
|
|
||||||
|
if ("statusCode" in pingResult) {
|
||||||
|
logger.debug(`executed ping for url ${url} with status code ${pingResult.statusCode}`);
|
||||||
|
} else {
|
||||||
|
logger.error(`Executing ping for url ${url} failed with error: ${pingResult.error}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await pingChannel.publishAsync({
|
||||||
|
url,
|
||||||
|
...pingResult,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user