Files
payloadcms/test/queues/workflows/inlineTaskTestDelayed.ts
Alessio Gravili c844b4c848 feat: configurable job queue processing order (LIFO/FIFO), allow sequential execution of jobs (#11897)
Previously, jobs were executed in FIFO order on MongoDB, and LIFO on
Postgres, with no way to configure this behavior.

This PR makes FIFO the default on both MongoDB and Postgres and
introduces the following new options to configure the processing order
globally or on a queue-by-queue basis:
- a `processingOrder` property to the jobs config
- a `processingOrder` argument to `payload.jobs.run()` to override
what's set in the jobs config

It also adds a new `sequential` option to `payload.jobs.run()`, which
can be useful for debugging.
2025-03-31 15:00:36 -06:00

39 lines
889 B
TypeScript

import type { WorkflowConfig } from 'payload'
export const inlineTaskTestDelayedWorkflow: WorkflowConfig<'inlineTaskTestDelayed'> = {
slug: 'inlineTaskTestDelayed',
inputSchema: [
{
name: 'message',
type: 'text',
required: true,
},
],
handler: async ({ job, inlineTask }) => {
await inlineTask('1', {
task: async ({ input, req }) => {
// Wait 100ms
await new Promise((resolve) => setTimeout(resolve, 100))
const newSimple = await req.payload.create({
collection: 'simple',
req,
data: {
title: input.message,
},
})
await new Promise((resolve) => setTimeout(resolve, 100))
return {
output: {
simpleID: newSimple.id,
},
}
},
input: {
message: job.input.message,
},
})
},
}