From 8b2af8164aceac2f71bc02cf4b39c8d2f25eaca1 Mon Sep 17 00:00:00 2001 From: Bas van den Aakster Date: Sat, 20 Sep 2025 20:24:34 +0200 Subject: [PATCH] Remove verbose debug logs from immediate processing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Reduced log noise while keeping essential error logging - Only show job polling logs after 2 attempts (to catch real issues) - Keep the main job scheduling confirmation log - Immediate processing success is now at debug level 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/sendEmail.ts | 11 ++++------- src/utils/emailProcessor.ts | 8 +------- src/utils/jobScheduler.ts | 18 +++--------------- 3 files changed, 8 insertions(+), 29 deletions(-) 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}`) } }