From eb69885a890ab06de4610d8a8f4fcce51152debc Mon Sep 17 00:00:00 2001 From: Anders Semb Hermansen Date: Mon, 30 Dec 2024 21:03:29 +0100 Subject: [PATCH] fix: close db connections after running jobs from command line. (#9994) ### What? Exit process after `payload jobs:run` without cron is executed ### Why? I would expect the `payload jobs:run` command to exit normally after execution. With mongodb this is not the case as database connections are open so the node process itself will not exit. ### How? Execute `payload.db.destroy` to close all db connections after queue is execution is done. Fixes: #9851 --- packages/payload/src/bin/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/payload/src/bin/index.ts b/packages/payload/src/bin/index.ts index 2d7d9363d49..637c8142958 100755 --- a/packages/payload/src/bin/index.ts +++ b/packages/payload/src/bin/index.ts @@ -102,10 +102,14 @@ export const bin = async () => { return } else { - return await payload.jobs.run({ + await payload.jobs.run({ limit, queue, }) + + await payload.db.destroy() // close database connections after running jobs so process can exit cleanly + + return } }