This simplifies workflow / task error handling, as well as cancelling jobs. Previously, we were handling errors when they occur and passing through error state using a `state` object - errors were then handled in multiple areas of the code. This PR adds new, clean `TaskError`, `WorkflowError` and `JobCancelledError` errors that are thrown when they occur and are handled **in one single place**, massively cleaning up complex functions like [payload/src/queues/operations/runJobs/runJob/getRunTaskFunction.ts](https://github.com/payloadcms/payload/compare/refactor/jobs-errors?expand=1#diff-53dc7ccb7c8e023c9ba63fdd2e78c32ad0be606a2c64a3512abad87893f5fd21) Performance will also be positively improved by this change - previously, as task / workflow failure or cancellation would have resulted in multiple, separate `updateJob` db calls, as data modifications to the job object required for storing failure state were done multiple times in multiple areas of the codebase. Most notably, task error state was handled and updated separately from workflow error state. Now, it's just a clean, single `updateJob` call This PR also does the following: - adds a new test for `deleteJobOnComplete` behavior - cleans up test suite - ensures `deleteJobOnComplete` does not delete definitively failed jobs --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210553277813320
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
import type { Payload, SanitizedConfig } from 'payload'
|
|
|
|
import path from 'path'
|
|
import { getPayload } from 'payload'
|
|
|
|
import { runInit } from '../runInit.js'
|
|
import { NextRESTClient } from './NextRESTClient.js'
|
|
|
|
/**
|
|
* Initialize Payload configured for integration tests
|
|
*/
|
|
export async function initPayloadInt<TInitializePayload extends boolean | undefined = true>(
|
|
dirname: string,
|
|
testSuiteNameOverride?: string,
|
|
initializePayload?: TInitializePayload,
|
|
): Promise<
|
|
TInitializePayload extends false
|
|
? { config: SanitizedConfig }
|
|
: { config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }
|
|
> {
|
|
const testSuiteName = testSuiteNameOverride ?? path.basename(dirname)
|
|
await runInit(testSuiteName, false, true)
|
|
console.log('importing config', path.resolve(dirname, 'config.ts'))
|
|
const { default: config } = await import(path.resolve(dirname, 'config.ts'))
|
|
|
|
if (initializePayload === false) {
|
|
return { config: await config } as any
|
|
}
|
|
|
|
console.log('starting payload')
|
|
|
|
const payload = await getPayload({ config })
|
|
console.log('initializing rest client')
|
|
const restClient = new NextRESTClient(payload.config)
|
|
console.log('initPayloadInt done')
|
|
return { config: payload.config, payload, restClient } as any
|
|
}
|