Skip to content

Commit

Permalink
fix: do not autorun jobs during next build process
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Jan 9, 2025
1 parent bdb96dd commit 595a742
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/payload/src/exports/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export { getSiblingData } from '../utilities/getSiblingData.js'

export { getUniqueListBy } from '../utilities/getUniqueListBy.js'

export { isNextBuild } from '../utilities/isNextBuild.js'

export { isNumber } from '../utilities/isNumber.js'

export { isPlainObject } from '../utilities/isPlainObject.js'
Expand All @@ -83,7 +85,6 @@ export { setsAreEqual } from '../utilities/setsAreEqual.js'
export { default as toKebabCase } from '../utilities/toKebabCase.js'

export { unflatten } from '../utilities/unflatten.js'

export { validateMimeType } from '../utilities/validateMimeType.js'
export { wait } from '../utilities/wait.js'
export { default as wordBoundariesRegex } from '../utilities/wordBoundariesRegex.js'
Expand Down
3 changes: 2 additions & 1 deletion packages/payload/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import { consoleEmailAdapter } from './email/consoleEmailAdapter.js'
import { fieldAffectsData } from './fields/config/types.js'
import localGlobalOperations from './globals/operations/local/index.js'
import { getJobsLocalAPI } from './queues/localAPI.js'
import { isNextBuild } from './utilities/isNextBuild.js'
import { getLogger } from './utilities/logger.js'
import { serverInit as serverInitTelemetry } from './utilities/telemetry/events/serverInit.js'
import { traverseFields } from './utilities/traverseFields.js'
Expand Down Expand Up @@ -714,7 +715,7 @@ export class BasePayload {
await this.config.onInit(this)
}
}
if (this.config.jobs.autoRun) {
if (this.config.jobs.autoRun && !isNextBuild()) {
const DEFAULT_CRON = '* * * * *'
const DEFAULT_LIMIT = 10

Expand Down
9 changes: 9 additions & 0 deletions packages/payload/src/utilities/isNextBuild.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Utility function to determine if the code is being executed during the Next.js build process.
*/
export function isNextBuild() {
return (
process.env.NEXT_PHASE === 'phase-production-build' ||
process.env.npm_lifecycle_event === 'build'
)
}

0 comments on commit 595a742

Please sign in to comment.