Zend certified PHP/Magento developer

Cron job generates a different output compared with a controller in Magento 2.4.1

I implemented a custom plugin that loops through all products and generates a CSV file.

Even if the execute() function has the same code in both files (cron job and controller), the CSV file generated is slightly different. The controller generates the CSV as expected, but the cron job is not doing that.

For example, the controller generates a CSV file with 1000+ products, but the cron job only 400 products. The images generated by the controller are the ones that are assigned to the products, but the ones generated by the cron job are only placeholder images.

I don’t know the source of these differences, but it is strange.

Are there any differences in Magento 2 between cron jobs and controllers that should be considered?

Thank you!