Adds a new `schedule` property to workflow and task configs that can be used to have Payload automatically _queue_ jobs following a certain _schedule_. Docs: https://payloadcms.com/docs/dynamic/jobs-queue/schedules?branch=feat/schedule-jobs ## API Example ```ts export default buildConfig({ // ... jobs: { // ... scheduler: 'manual', // Or `cron` if you're not using serverless. If `manual` is used, then user needs to set up running /api/payload-jobs/handleSchedules or payload.jobs.handleSchedules in regular intervals tasks: [ { schedule: [ { cron: '* * * * * *', queue: 'autorunSecond', // Hooks are optional hooks: { // Not an array, as providing and calling `defaultBeforeSchedule` would be more error-prone if this was an array beforeSchedule: async (args) => { // Handles verifying that there are no jobs already scheduled or processing. // You can override this behavior by not calling defaultBeforeSchedule, e.g. if you wanted // to allow a maximum of 3 scheduled jobs in the queue instead of 1, or add any additional conditions const result = await args.defaultBeforeSchedule(args) return { ...result, input: { message: 'This task runs every second', }, } }, afterSchedule: async (args) => { await args.defaultAfterSchedule(args) // Handles updating the payload-jobs-stats global args.req.payload.logger.info( 'EverySecond task scheduled: ' + (args.status === 'success' ? args.job.id : 'skipped or failed to schedule'), ) }, }, }, ], slug: 'EverySecond', inputSchema: [ { name: 'message', type: 'text', required: true, }, ], handler: ({ input, req }) => { req.payload.logger.info(input.message) return { output: {}, } }, } ] } }) ``` --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210495300843759
39 lines
1.3 KiB
TypeScript
39 lines
1.3 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,
|
|
configFile?: string,
|
|
): Promise<
|
|
TInitializePayload extends false
|
|
? { config: SanitizedConfig }
|
|
: { config: SanitizedConfig; payload: Payload; restClient: NextRESTClient }
|
|
> {
|
|
const testSuiteName = testSuiteNameOverride ?? path.basename(dirname)
|
|
await runInit(testSuiteName, false, true, configFile)
|
|
console.log('importing config', path.resolve(dirname, configFile ?? 'config.ts'))
|
|
const { default: config } = await import(path.resolve(dirname, configFile ?? 'config.ts'))
|
|
|
|
if (initializePayload === false) {
|
|
return { config: await config } as any
|
|
}
|
|
|
|
console.log('starting payload')
|
|
|
|
const payload = await getPayload({ config, cron: true })
|
|
console.log('initializing rest client')
|
|
const restClient = new NextRESTClient(payload.config)
|
|
console.log('initPayloadInt done')
|
|
return { config: payload.config, payload, restClient } as any
|
|
}
|