mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
fix: Update postBotStats to output status codes from request
This commit is contained in:
1 parent
6d12735dc5
commit
9e20805529
1 file changed
+17
-9
@@ -13,7 +13,6 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
|
|||||||
shardId: client.shard?.ids[0]
|
shardId: client.shard?.ids[0]
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
|
||||||
if (client.shard?.ids[0] !== 0) {
|
if (client.shard?.ids[0] !== 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -23,6 +22,7 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
|
|||||||
const shardCount: number = client.shard.count;
|
const shardCount: number = client.shard.count;
|
||||||
const shardId: number = client.shard.ids[0];
|
const shardId: number = client.shard.ids[0];
|
||||||
|
|
||||||
|
try {
|
||||||
logger.debug('Gathering data about guild and member count from shards...');
|
logger.debug('Gathering data about guild and member count from shards...');
|
||||||
await client!
|
await client!
|
||||||
.shard!.fetchClientValues('guilds.cache')
|
.shard!.fetchClientValues('guilds.cache')
|
||||||
@@ -40,6 +40,11 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
|
|||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
logger.error(error, 'Failed to fetch client values from shards.');
|
logger.error(error, 'Failed to fetch client values from shards.');
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error, 'Failed to gather data about guild and member count from shards.');
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`Starting to post bot stats with guild count ${guildCount} and member count ${memberCount}...`);
|
||||||
|
|
||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
const sites: PostBotStatsSite[] = [
|
const sites: PostBotStatsSite[] = [
|
||||||
@@ -122,13 +127,12 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
logger.info(`Starting to post bot stats with guild count ${guildCount} and member count ${memberCount}...`);
|
try {
|
||||||
|
const statusPromises = sites.map((site) => {
|
||||||
const statusCodes: number[] = [];
|
return new Promise<number | null>((resolve) => {
|
||||||
|
|
||||||
sites.map((site) => {
|
|
||||||
if (!site.enabled) {
|
if (!site.enabled) {
|
||||||
// return if site is disabled
|
// return if site is disabled
|
||||||
|
resolve(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,20 +153,24 @@ export const postBotStats = async ({ client, executionId }: PostBotStatsParams)
|
|||||||
res.statusCode === 200
|
res.statusCode === 200
|
||||||
? logger.debug(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
? logger.debug(`Request to ${site.hostname}: statusCode: ${res.statusCode}`)
|
||||||
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
: logger.warn(`Request to ${site.hostname}: statusCode: ${res.statusCode}`);
|
||||||
|
resolve(res.statusCode);
|
||||||
statusCodes.push(res.statusCode);
|
|
||||||
} else {
|
} else {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Request to ${site.hostname}: statusCode is undefined or not a number (${res.statusCode}).`
|
`Request to ${site.hostname}: statusCode is undefined or not a number (${res.statusCode}).`
|
||||||
);
|
);
|
||||||
|
resolve(null);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
request.write(JSON.stringify(site.body));
|
request.write(JSON.stringify(site.body));
|
||||||
request.end();
|
request.end();
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
logger.info(`Successfully posted bot stats with status codes ${statusCodes.join(', ')}.`);
|
const statusCodes = await Promise.all(statusPromises);
|
||||||
|
logger.info(
|
||||||
|
`Successfully posted bot stats with status codes ${statusCodes.filter((code) => code !== null).join(', ')}.`
|
||||||
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, 'Failed to post bot stats to sites.');
|
logger.error(error, 'Failed to post bot stats to sites.');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user