ℹ️ refactor: Remove use of Agenda for Conversation Imports (#3024)

* chore: remove agenda and npm audit fix

* refactor: import conversations without agenda

* chore: update package-lock.json and data-provider version to 0.6.7

* fix: import conversations

* chore: client npm audit fix
This commit is contained in:
Danny Avila 2024-06-10 13:00:34 -04:00 committed by GitHub
parent 92232afaca
commit 2e559137ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 52 additions and 402 deletions

View file

@ -0,0 +1,32 @@
const fs = require('fs').promises;
const { getImporter } = require('./importers');
const { indexSync } = require('~/lib/db');
const { logger } = require('~/config');
/**
* Job definition for importing a conversation.
* @param {{ filepath, requestUserId }} job - The job object.
*/
const importConversations = async (job) => {
const { filepath, requestUserId } = job;
try {
logger.debug(`user: ${requestUserId} | Importing conversation(s) from file...`);
const fileData = await fs.readFile(filepath, 'utf8');
const jsonData = JSON.parse(fileData);
const importer = getImporter(jsonData);
await importer(jsonData, requestUserId);
// Sync Meilisearch index
await indexSync();
logger.debug(`user: ${requestUserId} | Finished importing conversations`);
} catch (error) {
logger.error(`user: ${requestUserId} | Failed to import conversation: `, error);
} finally {
try {
await fs.unlink(filepath);
} catch (error) {
logger.error(`user: ${requestUserId} | Failed to delete file: ${filepath}`, error);
}
}
};
module.exports = importConversations;