Commit | Line | Data |
---|---|---|
9aef1431 JB |
1 | import { fileURLToPath } from 'node:url' |
2 | import { dirname, extname, join } from 'node:path' | |
3 | import { DynamicThreadPool, availableParallelism } from 'poolifier' | |
f8374594 | 4 | import type SMTPTransport from 'nodemailer/lib/smtp-transport/index.js' |
9aef1431 JB |
5 | import { type WorkerData } from './types.js' |
6 | ||
7 | const workerFile = join( | |
8 | dirname(fileURLToPath(import.meta.url)), | |
9 | `worker${extname(fileURLToPath(import.meta.url))}` | |
10 | ) | |
11 | ||
f8374594 JB |
12 | export const smtpClientPool = new DynamicThreadPool< |
13 | WorkerData, | |
14 | SMTPTransport.SentMessageInfo | |
15 | >(1, availableParallelism(), workerFile, { | |
16 | enableTasksQueue: true, | |
17 | tasksQueueOptions: { | |
18 | concurrency: 8 | |
19 | }, | |
20 | errorHandler: (e: Error) => { | |
21 | console.error('Thread worker error:', e) | |
9aef1431 | 22 | } |
f8374594 | 23 | }) |