mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 08:13:23 +00:00
- Replace createMailingJobs() function with static mailingJobs array
- Remove complex initialization dependencies and function wrappers
- Jobs now get MailingService from payload context instead of factory injection
- Fix PayloadCMS task handler return types to use proper {output: {}} format
- Eliminate potential initialization race conditions
- Cleaner, more straightforward job registration process
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
import { processEmailsJob, ProcessEmailsJobData } from './processEmailsJob.js'
|
|
import { sendEmailJob } from './sendEmailTask.js'
|
|
import { MailingService } from '../services/MailingService.js'
|
|
|
|
export const mailingJobs = [
|
|
{
|
|
slug: 'processEmails',
|
|
handler: async ({ job, req }: { job: any; req: any }) => {
|
|
// Get mailing context from payload
|
|
const payload = (req as any).payload
|
|
const mailingContext = payload.mailing
|
|
if (!mailingContext) {
|
|
throw new Error('Mailing plugin not properly initialized')
|
|
}
|
|
|
|
// Use the existing mailing service from context
|
|
await processEmailsJob(
|
|
job as { data: ProcessEmailsJobData },
|
|
{ req, mailingService: mailingContext.service }
|
|
)
|
|
|
|
return {
|
|
output: {
|
|
success: true,
|
|
message: 'Email queue processing completed successfully'
|
|
}
|
|
}
|
|
},
|
|
interfaceName: 'ProcessEmailsJob',
|
|
},
|
|
sendEmailJob,
|
|
]
|
|
|
|
export * from './processEmailsJob.js'
|
|
export * from './sendEmailTask.js' |