Skip to content

Commit

Permalink
Merge pull request #129 from TogetherCrew/redis-queue-retry-option
Browse files Browse the repository at this point in the history
[FIXBUG]: set redis attempts to 0
  • Loading branch information
cyri113 authored Oct 23, 2023
2 parents 0f7d921 + 5de538d commit 4164c0b
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 197 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ src/config/*.env
# compiled output
/dist
/node_modules
/lib

#migration
migrate.json
Expand Down
24 changes: 12 additions & 12 deletions src/functions/fetchMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function getNeedDataFromMessage(message: Message, threadInfo?: threadInfo)
channelName: threadInfo?.channelName ? threadInfo?.channelName : '',
threadId: threadInfo?.threadId ? threadInfo?.threadId : null,
threadName: threadInfo?.threadName ? threadInfo?.threadName : null,
isGeneratedByWebhook: message.webhookId ? true : false
isGeneratedByWebhook: message.webhookId ? true : false,
};
} else {
return {
Expand All @@ -83,7 +83,7 @@ async function getNeedDataFromMessage(message: Message, threadInfo?: threadInfo)
channelName: message.channel instanceof TextChannel ? message.channel.name : null,
threadId: null,
threadName: null,
isGeneratedByWebhook: message.webhookId ? true : false
isGeneratedByWebhook: message.webhookId ? true : false,
};
}
}
Expand Down Expand Up @@ -152,22 +152,22 @@ async function fetchMessages(
}
channel instanceof ThreadChannel
? await pushMessagesToArray(connection, messagesToStore, [...fetchedMessages.values()], {
threadId: channel.id,
threadName: channel.name,
channelId: channel.parent?.id,
channelName: channel.parent?.name,
})
threadId: channel.id,
threadName: channel.name,
channelId: channel.parent?.id,
channelName: channel.parent?.name,
})
: await pushMessagesToArray(connection, messagesToStore, [...fetchedMessages.values()]);
break;
}

channel instanceof ThreadChannel
? await pushMessagesToArray(connection, messagesToStore, [...fetchedMessages.values()], {
threadId: channel.id,
threadName: channel.name,
channelId: channel.parent?.id,
channelName: channel.parent?.name,
})
threadId: channel.id,
threadName: channel.name,
channelId: channel.parent?.id,
channelName: channel.parent?.name,
})
: await pushMessagesToArray(connection, messagesToStore, [...fetchedMessages.values()]);
options[fetchDirection] = boundaryMessage.id;
fetchedMessages = await channel.messages.fetch(options);
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ const client = new Client({

const partial =
(func: any, ...args: any) =>

Check warning on line 39 in src/index.ts

View workflow job for this annotation

GitHub Actions / test/node 18.x/ubuntu-latest

Unexpected any. Specify a different type

Check warning on line 39 in src/index.ts

View workflow job for this annotation

GitHub Actions / test/node 18.x/ubuntu-latest

Unexpected any. Specify a different type
(...rest: any) =>
func(...args, ...rest);
(...rest: any) =>

Check warning on line 40 in src/index.ts

View workflow job for this annotation

GitHub Actions / test/node 18.x/ubuntu-latest

Unexpected any. Specify a different type
func(...args, ...rest);

const fetchMethod = async (msg: any) => {

Check warning on line 43 in src/index.ts

View workflow job for this annotation

GitHub Actions / test/node 18.x/ubuntu-latest

Unexpected any. Specify a different type
logger.info({ msg }, 'fetchMethod is running');
Expand Down Expand Up @@ -179,7 +179,7 @@ async function app() {
// every: 10000
},
jobId: 'cronJob', // Optional: Provide a unique ID for the job
attempts: 1, // Number of times to retry the job if it fails
attempts: 0, // Number of times to retry the job if it fails
backoff: {
type: 'exponential',
delay: 1000, // Initial delay between retries in milliseconds
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,29 @@
import 'dotenv/config';
import { Client, GatewayIntentBits, } from 'discord.js';
import { Client, GatewayIntentBits } from 'discord.js';
import { guildService } from '../../database/services';
import { connectDB } from '../../database';
import { databaseService } from '@togethercrew.dev/db';
import config from '../../config';
import { closeConnection } from '../../database/connection';
import webhookLogic from '../utils/webhookLogic';

const {
Guilds,
GuildMembers,
GuildMessages,
GuildPresences,
DirectMessages
} = GatewayIntentBits;

const { Guilds, GuildMembers, GuildMessages, GuildPresences, DirectMessages } = GatewayIntentBits;

export const up = async () => {
const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages, GuildPresences, DirectMessages],
});
const client = new Client({
intents: [Guilds, GuildMembers, GuildMessages, GuildPresences, DirectMessages],
});

await client.login(config.discord.botToken);
await connectDB();
const guilds = await guildService.getGuilds({});
for (let i = 0; i < guilds.length; i++) {
const connection = databaseService.connectionFactory(guilds[i].guildId, config.mongoose.dbURL);
await webhookLogic(connection, client, guilds[i].guildId);
await closeConnection(connection);
}
await client.login(config.discord.botToken);
await connectDB();
const guilds = await guildService.getGuilds({});
for (let i = 0; i < guilds.length; i++) {
const connection = databaseService.connectionFactory(guilds[i].guildId, config.mongoose.dbURL);
await webhookLogic(connection, client, guilds[i].guildId);
await closeConnection(connection);
}
};

export const down = async () => {
// TODO: Implement rollback logic if needed
// TODO: Implement rollback logic if needed
};


11 changes: 5 additions & 6 deletions src/migrations/utils/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import 'dotenv/config';
import config from '../../config';

export const up = async () => {
await connectDB();
const connection = databaseService.connectionFactory("681946187490000803", config.mongoose.dbURL);
await connection.createCollection('my_collection');
await connectDB();
const connection = databaseService.connectionFactory('681946187490000803', config.mongoose.dbURL);
await connection.createCollection('my_collection');
};

export const down = async () => {
await connectDB()

};
await connectDB();
};
Loading

0 comments on commit 4164c0b

Please sign in to comment.