Skip to content

Commit

Permalink
add bin script
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessioGr committed Oct 4, 2024
1 parent 965fa32 commit 578a9cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/queues/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

12 changes: 12 additions & 0 deletions packages/payload/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}

0 comments on commit 578a9cf

Please sign in to comment.