bun + hono
This commit is contained in:
43
src/services/email.ts
Normal file
43
src/services/email.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { emailQueue } from '../queues/email.queue'
|
||||
import { config } from '../config/env'
|
||||
|
||||
interface EmailOptions {
|
||||
to: string
|
||||
subject: string
|
||||
html: string
|
||||
text: string
|
||||
}
|
||||
|
||||
export class EmailService {
|
||||
async sendEmail(options: EmailOptions): Promise<void> {
|
||||
const email = {
|
||||
from: config.email.from,
|
||||
...options
|
||||
}
|
||||
|
||||
// Add to queue instead of sending directly
|
||||
await emailQueue.add('send-email', email, {
|
||||
removeOnComplete: true,
|
||||
removeOnFail: 1000
|
||||
})
|
||||
|
||||
// Log for development
|
||||
await Bun.write('emails.log', JSON.stringify(email) + '\n', { append: true })
|
||||
}
|
||||
|
||||
async getQueueStatus() {
|
||||
const [waiting, active, completed, failed] = await Promise.all([
|
||||
emailQueue.getWaitingCount(),
|
||||
emailQueue.getActiveCount(),
|
||||
emailQueue.getCompletedCount(),
|
||||
emailQueue.getFailedCount()
|
||||
])
|
||||
|
||||
return {
|
||||
waiting,
|
||||
active,
|
||||
completed,
|
||||
failed
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user