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

[FIXBUG]: set redis attempts to 0 #129

Merged
merged 2 commits into from
Oct 23, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -36,11 +36,11 @@
});

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

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

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

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');
if (!msg) return;
const { content } = msg;
Expand Down Expand Up @@ -70,7 +70,7 @@
const guild = await client.guilds.fetch(guildId);
const channels = await guild.channels.fetch();

const arrayChannels = Array.from(channels, ([name, value]) => ({ ...value } as Channel));

Check warning on line 73 in src/index.ts

View workflow job for this annotation

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

'name' is defined but never used

Check warning on line 73 in src/index.ts

View workflow job for this annotation

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

'name' is defined but never used
const textChannels = arrayChannels.filter(channel => channel.type == ChannelType.GuildText) as TextChannel[];
const rawPositionBasedSortedTextChannels = textChannels.sort((textChannelA, textChannelB) =>
textChannelA.rawPosition > textChannelB.rawPosition ? 1 : -1
Expand Down Expand Up @@ -179,7 +179,7 @@
// 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 All @@ -190,7 +190,7 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const worker = new Worker(
'cronJobQueue',
async (job: Job<any, any, string> | undefined) => {

Check warning on line 193 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 193 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 193 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 193 in src/index.ts

View workflow job for this annotation

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

Unexpected any. Specify a different type
if (job) {
// Call the extractMessagesDaily function
await cronJob(client);
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
Loading