mirror of
https://github.com/xtr-dev/payload-mailing.git
synced 2025-12-11 00:33:23 +00:00
Add configurable logger with PAYLOAD_MAILING_LOG_LEVEL support
- Created centralized logger utility using Payload's built-in logger system - Added PAYLOAD_MAILING_LOG_LEVEL environment variable for log level configuration - Replaced all console.log/error/warn calls with structured logger - Added debug logging for immediate processing flow to help troubleshoot issues - Improved logging context with specific prefixes (IMMEDIATE, PROCESSOR, JOB_SCHEDULER, etc.) - Bumped version to 0.4.10 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { Payload } from 'payload'
|
||||
import { createContextLogger } from './logger.js'
|
||||
|
||||
/**
|
||||
* Processes a single email by ID using the mailing service
|
||||
@@ -36,20 +37,28 @@ export async function processEmailById(payload: Payload, emailId: string): Promi
|
||||
* @returns Promise that resolves when job is processed
|
||||
*/
|
||||
export async function processJobById(payload: Payload, jobId: string): Promise<void> {
|
||||
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)
|
||||
await payload.jobs.run({
|
||||
const result = await payload.jobs.run({
|
||||
where: {
|
||||
id: {
|
||||
equals: jobId
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.info(`Job ${jobId} execution completed`, { result })
|
||||
} catch (error) {
|
||||
logger.error(`Job ${jobId} execution failed:`, error)
|
||||
throw new Error(`Failed to process job ${jobId}: ${String(error)}`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user