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