Why does autoRun and onInit only trigger after the first HTTP request in Next.js production? #16284
Unanswered
shestakov2103
asked this question in
Q&A
Replies: 1 comment 2 replies
-
|
We solved it with a health check so that it is initialized. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi
I've noticed a significant difference in behavior between the CLI runner and the Web server in Payload 3.0.
If I run pnpm payload jobs:run --handle-schedules, everything starts immediately and works perfectly.
If I rely on autoRun inside the main Next.js app (npm run start), the worker and onInit hooks remain idle until I manually open the admin panel in a browser.
I understand that Next.js uses lazy initialization, but for background workers, this is a major issue. We expect the worker to start as soon as the Node process starts, not when the first user logs in.
Is there a way to force "Eager Initialization" for Payload within the Next.js process without resorting to running a separate CLI worker? Or is a separate CLI process now the officially recommended way for production background tasks?
Beta Was this translation helpful? Give feedback.
All reactions