From 578a9cf116e31eed739fac14ce8ec5e35bdc1ce4 Mon Sep 17 00:00:00 2001 From: Alessio Gravili Date: Fri, 4 Oct 2024 17:52:36 +0200 Subject: [PATCH] add bin script --- docs/queues/overview.mdx | 9 ++++++++- packages/payload/src/bin/index.ts | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/queues/overview.mdx b/docs/queues/overview.mdx index 4cc373c30b4..33e37fb78f6 100644 --- a/docs/queues/overview.mdx +++ b/docs/queues/overview.mdx @@ -254,9 +254,16 @@ Run the payload.jobs.run function: const results = await payload.jobs.run() // You can customize the queue name by passing it as an argument - await payload.jobs.run({ queue: 'posts' }) +``` + +### Script +You can run the jobs:run script from the command line: + +```sh +npx payload jobs:run --queue default --limit 10 ``` ## Triggering workflows and task runs via node-cron + diff --git a/packages/payload/src/bin/index.ts b/packages/payload/src/bin/index.ts index 97633b514b1..72d39e4eab6 100755 --- a/packages/payload/src/bin/index.ts +++ b/packages/payload/src/bin/index.ts @@ -5,6 +5,7 @@ import path from 'path' import type { BinScript } from '../config/types.js' import { findConfig } from '../config/find.js' +import { getPayload } from '../index.js' import { generateImportMap } from './generateImportMap/index.js' import { generateTypes } from './generateTypes.js' import { info } from './info.js' @@ -83,6 +84,17 @@ export const bin = async () => { return generateImportMap(config) } + if (script === 'jobs:run') { + const payload = await getPayload(config) + const limit = args.limit ? parseInt(args.limit, 10) : undefined + const queue = args.queue ? args.queue : undefined + + return await payload.jobs.run({ + limit, + queue, + }) + } + console.error(`Unknown script: "${script}".`) process.exit(1) }