diff --git a/package.json b/package.json index 8d18e89..fb49b46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@xtr-dev/payload-mailing", - "version": "0.4.11", + "version": "0.4.12", "description": "Template-based email system with scheduling and job processing for PayloadCMS", "type": "module", "main": "dist/index.js", diff --git a/src/sendEmail.ts b/src/sendEmail.ts index b5cfb4d..710b809 100644 --- a/src/sendEmail.ts +++ b/src/sendEmail.ts @@ -139,7 +139,6 @@ export const sendEmail = async 0) { // Job found! Get the first job ID (should only be one for a new email) const firstJob = Array.isArray(emailWithJobs.jobs) ? emailWithJobs.jobs[0] : emailWithJobs.jobs jobId = typeof firstJob === 'string' ? firstJob : String(firstJob.id || firstJob) - logger.info(`Found job ID: ${jobId}`) break } // Log on later attempts to help with debugging (reduced threshold) if (attempt >= 1) { - logger.debug(`Waiting for job creation for email ${email.id}, attempt ${attempt + 1}/${maxAttempts}`) + if (attempt >= 2) { + logger.debug(`Waiting for job creation for email ${email.id}, attempt ${attempt + 1}/${maxAttempts}`) + } } } @@ -212,10 +210,9 @@ export const sendEmail = async { - const logger = createContextLogger(payload, 'PROCESSOR') - logger.debug(`Starting processJobById for job ${jobId}`) - if (!payload.jobs) { throw new Error('PayloadCMS jobs not configured - cannot process job immediately') } try { - logger.debug(`Running job ${jobId} with payload.jobs.run()`) - // Run a specific job by its ID (using where clause to find the job) const result = await payload.jobs.run({ where: { @@ -55,9 +50,8 @@ export async function processJobById(payload: Payload, jobId: string): Promise 0) { // Found existing jobs - return them (race condition handled successfully) - logger.info(`Using existing jobs for email ${normalizedEmailId}: ${existingJobs.docs.map(j => j.id).join(', ')}`) + logger.debug(`Using existing jobs for email ${normalizedEmailId}: ${existingJobs.docs.map(j => j.id).join(', ')}`) return { jobIds: existingJobs.docs.map(job => job.id), created: false @@ -109,7 +97,7 @@ export async function ensureEmailJob( if (isLikelyUniqueConstraint) { // This should not happen if our check above worked, but provide a clear error - logger.error(`Unique constraint violation but no existing jobs found for email ${normalizedEmailId}`) + logger.warn(`Unique constraint violation but no existing jobs found for email ${normalizedEmailId}`) throw new Error( `Database uniqueness constraint violation for email ${normalizedEmailId}, but no existing jobs found. ` + `This indicates a potential data consistency issue. Original error: ${errorMessage}` @@ -117,7 +105,7 @@ export async function ensureEmailJob( } // Non-constraint related error - logger.error(`Non-constraint job creation error for email ${normalizedEmailId}: ${errorMessage}`) + logger.error(`Job creation error for email ${normalizedEmailId}: ${errorMessage}`) throw new Error(`Failed to create job for email ${normalizedEmailId}: ${errorMessage}`) } }