The vercel cron job does not work but the endpoint works fine on localhost.
Answered
Ivan2 posted this in #help-forum
Ivan2OP
I am trying to generate a cron job that deletes images with a certain condition in an aws s3 but when I try to run it in vercel the logs appear but it doesn't throw errors nor delete the images as it does in local. I have a pro account so I have no limit in the amount of cron jobs. I get the logs of the images to delete with the keys but it doesn't finish deleting them and I don't get error logs either. I am using the next 13 version.
Answered by Ray
try using for-of instead of forEach
for (const img of images) {
// your code
}4 Replies
@Ivan2 I am trying to generate a cron job that deletes images with a certain condition in an aws s3 but when I try to run it in vercel the logs appear but it doesn't throw errors nor delete the images as it does in local. I have a pro account so I have no limit in the amount of cron jobs. I get the logs of the images to delete with the keys but it doesn't finish deleting them and I don't get error logs either. I am using the next 13 version.
try using for-of instead of forEach
for (const img of images) {
// your code
}Answer
forEach() expects a synchronous function — it does not wait for promises. Make sure you are aware of the implications while using promises (or async functions) as forEach callbacks.https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach
Cape lion
I am having the exact same problem, @Ray maybe you can help out?
This works when I hit the endpoint manually at /api/cron and I know it works because the database is updated. I deployed to Vercel but and I am getting status 200 each time but I am not seeing the updates reflected in the database. Any idea what I am doing wrong? I am totally stuck. @Multiflora rose seed chalcid
This works when I hit the endpoint manually at /api/cron and I know it works because the database is updated. I deployed to Vercel but and I am getting status 200 each time but I am not seeing the updates reflected in the database. Any idea what I am doing wrong? I am totally stuck. @Multiflora rose seed chalcid