Merge pull request #61 from xtr-dev/dev

Remove deprecated `processEmailsTask` and associated helpers
This commit is contained in:
Bas
2025-09-27 11:49:44 +02:00
committed by GitHub
5 changed files with 4 additions and 97 deletions

View File

@@ -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",

View File

@@ -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'

View File

@@ -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

View File

@@ -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)
}
}

View File

@@ -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) {