Skip to content

Commit

Permalink
chore: relax logging for jobs (#8940)
Browse files Browse the repository at this point in the history
Prevents potentially leaking sensitive info in the logs and cuts down on
job logging in general
  • Loading branch information
DanRibbens authored Oct 30, 2024
1 parent 4726428 commit 50f2ffa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
8 changes: 1 addition & 7 deletions packages/payload/src/queues/operations/runJobs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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)
Expand All @@ -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({
Expand All @@ -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,
Expand Down

0 comments on commit 50f2ffa

Please sign in to comment.