Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: relax logging for jobs #8940

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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