pm2
pm2 copied to clipboard
PM2 Scheduled Cron Jobs Not Fetching Data from API after Update
What's going wrong?
I've been using PM2 to manage my Node.js applications for over a year. These applications fetch data from a REST API every 20 minutes, five days a week, and save the results to a database, including the date and time of the fetch.
This setup worked perfectly until a few months ago when I updated PM2 to a new version (unfortunately, I don't recall the exact version). After the update, the cron jobs still execute as scheduled, but the API's response is unexpectedly empty, even though the same request URL returns over 100 objects when tested through Postman.
Here are some steps I've taken to debug:
-
Verified the request URL by logging it and adjusting the cron schedule to hourly. The URL includes a lastModifiedDate parameter, which is dynamically obtained from the database to fetch new data.
-
Confirmed that manually reloading the PM2 process using pm2 reload somehow causes the application to receive the expected data from the API. Despite upgrading to PM2 version 5.3.1, the issue persists. Here are some additional details that might be relevant:
-
The Node.js and PM2 configurations have not changed, aside from the PM2 update. No errors are logged by the application or PM2, making this issue particularly puzzling.
-
I'm stumped as to why scheduled executions fail to fetch data correctly but manually reloading the process works. Has anyone encountered a similar issue or can offer insights into potential causes or solutions?
Additional Information:
PM2 version: 5.3.1 Node.js version: v20.2.0
Attempted Solutions:
- Verifying network connectivity and API rate limits
- Checking for changes in the API's behavior or data structure
I appreciate any help or suggestions you can provide. Thank you!
I'm afraid that without posting the exact code you're using this is extremely hard to solve based on this information. If possible, share the entire code (you can send it to me privately too if you wish, I will have a look for you).
- Did you happen to upgrade anything else besides PM2?
- Are you relying on environment variables in your script?
- Are you getting the current working directory?
- Is PM2 installed globally or as dependency of your app?
- Which package are you using to fetch the API?
- node-cron was replaced by croner in 5.2.0, maybe that's an angle to investigate