mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 00:03:23 +00:00
Remove deprecated processEmailsTask and associated helpers
- Deleted batch email processing logic in favor of individual email jobs - Updated `mailingJobs` to only register `processEmailJob` - Simplified LiquidJS initialization check in `MailingService` - Bumped version to 0.4.13
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@xtr-dev/payload-mailing",
|
||||
"version": "0.4.12",
|
||||
"version": "0.4.13",
|
||||
"description": "Template-based email system with scheduling and job processing for PayloadCMS",
|
||||
"type": "module",
|
||||
"main": "dist/index.js",
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
import { processEmailsJob } from './processEmailsTask.js'
|
||||
import { processEmailJob } from './processEmailJob.js'
|
||||
|
||||
/**
|
||||
* All mailing-related jobs that get registered with Payload
|
||||
*
|
||||
* Note: The sendEmailJob has been removed as each email now gets its own individual processEmailJob
|
||||
*/
|
||||
export const mailingJobs = [
|
||||
processEmailsJob, // Kept for backward compatibility and batch processing if needed
|
||||
processEmailJob, // New individual email processing job
|
||||
processEmailJob,
|
||||
]
|
||||
|
||||
// Re-export everything from individual job files
|
||||
export * from './processEmailsTask.js'
|
||||
export * from './processEmailJob.js'
|
||||
|
||||
@@ -13,7 +13,6 @@ export interface ProcessEmailJobInput {
|
||||
|
||||
/**
|
||||
* Job definition for processing a single email
|
||||
* This replaces the batch processing approach with individual email jobs
|
||||
*/
|
||||
export const processEmailJob = {
|
||||
slug: 'process-email',
|
||||
@@ -69,4 +68,4 @@ export const processEmailJob = {
|
||||
}
|
||||
}
|
||||
|
||||
export default processEmailJob
|
||||
export default processEmailJob
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
import type { PayloadRequest, Payload } from 'payload'
|
||||
import { processAllEmails } from '../utils/emailProcessor.js'
|
||||
import { createContextLogger } from '../utils/logger.js'
|
||||
|
||||
/**
|
||||
* Data passed to the process emails task
|
||||
*/
|
||||
export interface ProcessEmailsTaskData {
|
||||
// Currently no data needed - always processes both pending and failed emails
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler function for processing emails
|
||||
* Used internally by the task definition
|
||||
*/
|
||||
export const processEmailsTaskHandler = async (
|
||||
job: { data: ProcessEmailsTaskData },
|
||||
context: { req: PayloadRequest }
|
||||
) => {
|
||||
const { req } = context
|
||||
const payload = (req as any).payload
|
||||
|
||||
// Use the shared email processing logic
|
||||
await processAllEmails(payload)
|
||||
}
|
||||
|
||||
/**
|
||||
* Task definition for processing emails
|
||||
* This is what gets registered with Payload's job system
|
||||
*/
|
||||
export const processEmailsTask = {
|
||||
slug: 'process-emails',
|
||||
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 task handler
|
||||
await processEmailsTaskHandler(
|
||||
job as { data: ProcessEmailsTaskData },
|
||||
{ req }
|
||||
)
|
||||
|
||||
return {
|
||||
output: {
|
||||
success: true,
|
||||
message: 'Email queue processing completed successfully'
|
||||
}
|
||||
}
|
||||
},
|
||||
interfaceName: 'ProcessEmailsTask',
|
||||
}
|
||||
|
||||
// For backward compatibility, export as processEmailsJob
|
||||
export const processEmailsJob = processEmailsTask
|
||||
|
||||
/**
|
||||
* Helper function to schedule an email processing job
|
||||
* Used by the plugin during initialization and can be used by developers
|
||||
*/
|
||||
export const scheduleEmailsJob = async (
|
||||
payload: Payload,
|
||||
queueName: string,
|
||||
delay?: number
|
||||
) => {
|
||||
if (!payload.jobs) {
|
||||
const logger = createContextLogger(payload, 'SCHEDULER')
|
||||
logger.warn('PayloadCMS jobs not configured - emails will not be processed automatically')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
await payload.jobs.queue({
|
||||
queue: queueName,
|
||||
task: 'process-emails',
|
||||
input: {},
|
||||
waitUntil: delay ? new Date(Date.now() + delay) : undefined,
|
||||
} as any)
|
||||
} catch (error) {
|
||||
const logger = createContextLogger(payload, 'SCHEDULER')
|
||||
logger.error('Failed to schedule email processing job:', error)
|
||||
}
|
||||
}
|
||||
@@ -366,7 +366,7 @@ export class MailingService implements IMailingService {
|
||||
if (engine === 'liquidjs') {
|
||||
try {
|
||||
await this.ensureLiquidJSInitialized()
|
||||
if (this.liquid && typeof this.liquid !== 'boolean') {
|
||||
if (this.liquid) {
|
||||
return await this.liquid.parseAndRender(template, variables)
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user