mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-13 09:43:24 +00:00
Refactor and clean up job organization
- Properly encapsulate processEmailsJob in its own file with handler and definition - Clean up index.ts to remove duplicate code and just export job definitions - Add comprehensive JSDoc comments for better documentation - Separate job handler logic from job definition for clarity - Fix job scheduling to use correct field names - Bump version to 0.2.1
This commit is contained in:
@@ -1,35 +1,14 @@
|
||||
import { processEmailsJob, ProcessEmailsJobData } from './processEmailsJob.js'
|
||||
import { processEmailsJob } from './processEmailsJob.js'
|
||||
import { sendEmailJob } from './sendEmailTask.js'
|
||||
import { MailingService } from '../services/MailingService.js'
|
||||
|
||||
/**
|
||||
* All mailing-related jobs that get registered with Payload
|
||||
*/
|
||||
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',
|
||||
},
|
||||
processEmailsJob,
|
||||
sendEmailJob,
|
||||
]
|
||||
|
||||
// Re-export everything from individual job files
|
||||
export * from './processEmailsJob.js'
|
||||
export * from './sendEmailTask.js'
|
||||
export * from './sendEmailTask.js'
|
||||
|
||||
Reference in New Issue
Block a user