@xtr-dev/payload-mailing
Version:
Template-based email system with scheduling and job processing for PayloadCMS
58 lines (57 loc) • 1.58 kB
JavaScript
import { processEmailById } from '../utils/emailProcessor.js';
/**
* Job definition for processing a single email
* This replaces the batch processing approach with individual email jobs
*/
export const processEmailJob = {
slug: 'process-email',
label: 'Process Individual Email',
inputSchema: [
{
name: 'emailId',
type: 'text',
required: true,
label: 'Email ID',
admin: {
description: 'The ID of the email to process and send'
}
}
],
outputSchema: [
{
name: 'success',
type: 'checkbox'
},
{
name: 'emailId',
type: 'text'
},
{
name: 'status',
type: 'text'
}
],
handler: async ({ input, req }) => {
const payload = req.payload;
const { emailId } = input;
if (!emailId) {
throw new Error('Email ID is required for processing');
}
try {
// Process the individual email
await processEmailById(payload, String(emailId));
return {
output: {
success: true,
emailId: String(emailId),
status: 'sent',
message: `Email ${emailId} processed successfully`
}
};
}
catch (error) {
throw new Error(`Failed to process email ${emailId}: ${String(error)}`);
}
}
};
export default processEmailJob;