mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-10 08:13:23 +00:00
Remove verbose debug logs from immediate processing
- 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 <noreply@anthropic.com>
This commit is contained in:
@@ -49,15 +49,12 @@ export async function ensureEmailJob(
|
||||
const queueName = options?.queueName || mailingContext?.config?.queue || 'default'
|
||||
|
||||
const logger = createContextLogger(payload, 'JOB_SCHEDULER')
|
||||
logger.debug(`Ensuring job for email ${normalizedEmailId}`)
|
||||
logger.debug(`Queue: ${queueName}, scheduledAt: ${options?.scheduledAt || 'immediate'}`)
|
||||
|
||||
// First, optimistically try to create the job
|
||||
// If it fails due to uniqueness constraint, then check for existing jobs
|
||||
// This approach minimizes the race condition window
|
||||
|
||||
try {
|
||||
logger.debug(`Attempting to create new job for email ${normalizedEmailId}`)
|
||||
// Attempt to create job - rely on database constraints for duplicate prevention
|
||||
const job = await payload.jobs.queue({
|
||||
queue: queueName,
|
||||
@@ -69,31 +66,22 @@ export async function ensureEmailJob(
|
||||
})
|
||||
|
||||
logger.info(`Auto-scheduled processing job ${job.id} for email ${normalizedEmailId}`)
|
||||
logger.debug(`Job details`, {
|
||||
jobId: job.id,
|
||||
emailId: normalizedEmailId,
|
||||
scheduledAt: options?.scheduledAt || 'immediate',
|
||||
task: 'process-email',
|
||||
queue: queueName
|
||||
})
|
||||
|
||||
return {
|
||||
jobIds: [job.id],
|
||||
created: true
|
||||
}
|
||||
} catch (createError) {
|
||||
logger.warn(`Job creation failed for email ${normalizedEmailId}: ${String(createError)}`)
|
||||
|
||||
// Job creation failed - likely due to duplicate constraint or system issue
|
||||
|
||||
// Check if duplicate jobs exist (handles race condition where another process created job)
|
||||
const existingJobs = await findExistingJobs(payload, normalizedEmailId)
|
||||
|
||||
logger.debug(`Found ${existingJobs.totalDocs} existing jobs after creation failure`)
|
||||
|
||||
if (existingJobs.totalDocs > 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}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user