Uhm excuse me, but what the fuck

This commit is contained in:
2024-09-30 22:56:17 +02:00
parent 4f9a1bc879
commit da8ef9fa65
3 changed files with 67 additions and 66 deletions

View File

@ -49,41 +49,41 @@ class QueueManager {
}
private async processJob(job: Job) {
const { jobName, params, socketId } = job.data
const { jobName, params, socketId } = job.data;
const jobsDir = path.join(process.cwd(), 'src', 'jobs');
const extension = config.ENV === 'development' ? '.ts' : '.js';
const jobPath = path.join(jobsDir, `${jobName}${extension}`);
queueLogger.info(`Processing job: ${jobName}`);
if (!fs.existsSync(jobPath)) {
queueLogger.warn(`Job file not found: ${jobPath}`);
return;
}
try {
const jobsDir = path.join(process.cwd(), 'src', 'jobs')
const extension = config.ENV === 'development' ? '.ts' : '.js'
const jobPath = path.join(jobsDir, `${jobName}${extension}`)
if (!fs.existsSync(jobPath)) {
queueLogger.warn(`Job file not found: ${jobPath}`)
return
const module = await import(jobPath);
if (typeof module.default !== 'function') {
queueLogger.warn(`Unrecognized export in ${jobName}`);
return;
}
const JobModule = await import(jobPath)
const JobClass = JobModule.default
if (!JobClass || typeof JobClass !== 'function') {
queueLogger.warn(`Invalid job class in file: ${jobPath}`)
return
}
const jobInstance = new JobClass(params)
const JobClass = module.default;
const jobInstance = new JobClass(params);
if (socketId && this.io) {
const socket = this.io.sockets.sockets.get(socketId)
const socket = this.io.sockets.sockets.get(socketId);
if (socket) {
await jobInstance.execute(this.io, socket)
await jobInstance.execute(this.io, socket);
} else {
queueLogger.warn(`Socket not found for job: ${socketId}`)
await jobInstance.execute(this.io)
queueLogger.warn(`Socket not found for job: ${socketId}`);
await jobInstance.execute(this.io);
}
} else {
await jobInstance.execute(this.io)
await jobInstance.execute(this.io);
}
} catch (error: any) {
queueLogger.error(`Error processing job ${jobName}: ${error.message}`)
} catch (error) {
queueLogger.error(`Error processing job ${jobName}: ${error instanceof Error ? error.message : String(error)}`);
}
}