Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Fix recovery logic and add more logs
Browse files Browse the repository at this point in the history
  • Loading branch information
HippieBeak committed Apr 26, 2023
1 parent 1238b26 commit cf40dfd
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/util/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export async function startNotifier(database: Database, domain: string, apiKey:
statusMessage(MessageType.Info, `Sending messages to ${totalUsers} users... Estimated time: ${(totalUsers - userCount[0]) * 21 / 3600} hours`);

for (let i = userCount[0]; i < totalUsers; i++) {
userCount = [i]
const pmRequest = await enjinRequest<Messages.SendMessage> ({
recipients: [users[i].user_id],
message_subject: messageSubject,
Expand All @@ -57,9 +58,9 @@ export async function startNotifier(database: Database, domain: string, apiKey:

if (pmRequest.error) {
statusMessage(MessageType.Error, `Error sending message to ${users[i].user_id} ${users[i].username}: ${pmRequest.error.code}, ${pmRequest.error.message}`);
statusMessage(MessageType.Process, `Skipping ${users[i].user_id} ${users[i].username} [(++${userCount[0]}/${totalUsers})]`);
if (pmRequest.error.message.startsWith('This user has chosen to only')) {
await insertRow(database, 'private_users', users[i].user_id, users[i].username);
statusMessage(MessageType.Process, `Skipping ${users[i].user_id} ${users[i].username} [(++${userCount[0]}/${totalUsers})]`);
} else {
const match = pmRequest.error.message.match(/Please wait (\d+) (\w+) before sending another message\./)
if (match) {
Expand All @@ -77,6 +78,7 @@ export async function startNotifier(database: Database, domain: string, apiKey:
statusMessage(MessageType.Error, `Did not expect unit ${unit}... Exiting...`);
process.kill(process.pid, 'SIGINT');
}
statusMessage(MessageType.Process, `Waiting ${timeInMilliseconds}ms (${time} ${unit}) before trying ${users[i].user_id} ${users[i].username} again...`);
await new Promise((resolve) => setTimeout(resolve, timeInMilliseconds + 1000));

// Retry the user.
Expand Down

0 comments on commit cf40dfd

Please sign in to comment.