Repository navigation
feat!: replace BaseJob with a single Job type, enable job stats and meta field - #17504
Conversation
…ations # Conflicts: # packages/payload/src/config/defaults.ts # packages/payload/src/queues/config/types/index.ts # packages/payload/src/queues/config/types/workflowTypes.ts
| config.i18n = config.i18n ?? {} | ||
| config.jobs = { | ||
| deleteJobOnComplete: true, | ||
| depth: 0, |
There was a problem hiding this comment.
Property no longer exists. Typescript error was hidden by the as JobsConfig assertion below
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
| } | ||
| collections: { | ||
| [slug: string]: JsonObject & TypeWithID | ||
| 'payload-jobs': { |
There was a problem hiding this comment.
The goal: rely on automatic fallbacks for same access paths that a user would take in a real project.
So in a real project, a user can do PayloadTypes['collections']['payload-jobs']. I want to be able to do that within payload internally too.
We can add other internally managed collection types in here in the future, e.g. types for payload-preferences, payload-locked-documents, etc.
| ? true | ||
| : false | ||
| : false | ||
| type JobDocument = PayloadTypes['collections'] extends { |
There was a problem hiding this comment.
Question: why not just PayloadTypes['collections']['payload-jobs']?
Answer: when a project has generated types, but jobs are not enabled, we want it to fall back to the fallback jobs type.
Alternative: we fall back to never instead of the fallback jobs type
JarrodMFlesch
left a comment
There was a problem hiding this comment.
It feels like we should be more explicit about when you need to perform a db level migration here. What is the criteria, jobs enabled and using sqlite or pg? Do we have a migration we can provide users or more guidance?
This will be handled in a separate PR. SQL database users will need to run a migration in any case. Since several job queue PRs will introduce their own migration requirements, I’m intentionally keeping the details vague here. The migration PR will provide a single predefined migration covering all v4 job queue changes and updating the v4.mdx with specific steps. |
This PR removes the deprecated
BaseJobtype and makesJobthe single type for queued jobs.Jobnow uses the generatedpayload-jobscollection type when it is available. When generated job types are not available, it uses a fallback defined inUntypedPayloadTypes.What changed
One job type
The public
BaseJobtype has been removed.Jobnow automatically uses the generatedpayload-jobscollection type when it exists and the default job document fromUntypedPayloadTypes['collections']when it does not.Simpler workflow types
Workflow type generics are now simpler. They now accept either a workflow slug or an input object. They no longer use
falseas a fallback value. This reduces the data types accepted by this generic from 3 (false / object / slug string) to 2 (object / slug string).Default job metadata
The
payload-jobs-statsglobal and the jobmetafield are now always added whenever jobs are enabled. They are no longer opt-in. This requires a database migration.Why
Previously, core code had to choose between
JobandBaseJobdepending on whether generated types existed. This made job types harder to understand and caused different parts of the codebase to use different fallback logic.Now there is one
Jobtype with one automatic fallback. Core code can use the same collection access pattern that users use:Breaking changes
BaseJobis no longer exported and should be replaced withJob.Job and workflow generics now use
objectas their default instead offalse.Projects with jobs enabled will always include the
payload-jobs-statsglobal and the jobmetafield. Existing projects may need a database migration for these managed fields.