From 50f2ffa608f7b4d1137133152277ba442a957dfd Mon Sep 17 00:00:00 2001 From: Dan Ribbens Date: Wed, 30 Oct 2024 13:33:07 -0400 Subject: [PATCH] chore: relax logging for jobs (#8940) Prevents potentially leaking sensitive info in the logs and cuts down on job logging in general --- .../src/queues/operations/runJobs/index.ts | 8 +------- .../runJobs/runJob/handleWorkflowError.ts | 19 +++++++++---------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/packages/payload/src/queues/operations/runJobs/index.ts b/packages/payload/src/queues/operations/runJobs/index.ts index 0ed43362a80..cfca8032d0a 100644 --- a/packages/payload/src/queues/operations/runJobs/index.ts +++ b/packages/payload/src/queues/operations/runJobs/index.ts @@ -89,10 +89,6 @@ export const runJobs = async ({ }) } - req.payload.logger.info({ - msg: `Querying for ${limit} jobs.`, - }) - // Find all jobs and ensure we set job to processing: true as early as possible to reduce the chance of // the same job being picked up by another worker const jobsQuery = (await req.payload.update({ @@ -132,9 +128,7 @@ export const runJobs = async ({ } if (jobsQuery?.docs?.length) { - req.payload.logger.info( - `${jobsQuery.docs.length} job(s) found, ${newJobs.length} of which are new. Running ${limit} job(s).`, - ) + req.payload.logger.info(`Running ${jobsQuery.docs.length} jobs.`) } const jobPromises = jobsQuery.docs.map(async (job) => { diff --git a/packages/payload/src/queues/operations/runJobs/runJob/handleWorkflowError.ts b/packages/payload/src/queues/operations/runJobs/runJob/handleWorkflowError.ts index f5bccd58e66..15f58622113 100644 --- a/packages/payload/src/queues/operations/runJobs/runJob/handleWorkflowError.ts +++ b/packages/payload/src/queues/operations/runJobs/runJob/handleWorkflowError.ts @@ -5,7 +5,7 @@ import type { RunTaskFunctionState } from './getRunTaskFunction.js' import { calculateBackoffWaitUntil } from './calculateBackoffWaitUntil.js' /** - * This is called if a workflow catched an error. It determines if it's a final error + * This is called if a workflow catches an error. It determines if it's a final error * or not and handles logging. */ export function handleWorkflowError({ @@ -24,12 +24,12 @@ export function handleWorkflowError({ hasFinalError: boolean } { let hasFinalError = state.reachedMaxRetries // If any TASK reached max retries, the job has an error + const maxRetries = + typeof workflowConfig.retries === 'object' + ? workflowConfig.retries.attempts + : workflowConfig.retries // Now let's handle workflow retries if (!hasFinalError && workflowConfig.retries) { - const maxRetries = - typeof workflowConfig.retries === 'object' - ? workflowConfig.retries.attempts - : workflowConfig.retries if (job.waitUntil) { // Check if waitUntil is in the past const waitUntil = new Date(job.waitUntil) @@ -41,10 +41,6 @@ export function handleWorkflowError({ if (job.totalTried >= maxRetries) { state.reachedMaxRetries = true hasFinalError = true - - req.payload.logger.error({ - msg: 'Job has reached the maximum amount of retries determined by the workflow configuration.', - }) } else { // Job will retry. Let's determine when! const waitUntil: Date = calculateBackoffWaitUntil({ @@ -59,7 +55,10 @@ export function handleWorkflowError({ } } - req.payload.logger.error({ err: error, job, msg: 'Error running job' }) + req.payload.logger.error({ + err: error, + msg: `Error running job ${job.workflowSlug} ${job.taskSlug} id: ${job.id} attempt ${job.totalTried}/${maxRetries}`, + }) return { hasFinalError,