I am developing a Drupal Cron that has a very long-running task. First I tried with a simple Cron, which, of course, did not work because of "Memory exhausted" PHP fatal error.
Then, I developed a Batch with the Batch API which worked fine as a normal Batch. However, I could not make to run it completely inside the Cron. It receives the same PHP error.
After that, I developed a Cron using the Queue API. However, I could not make Drupal to run all queue jobs in the same cron. The execution stops at some point and I am unable to run more jobs. I know that there is an option to define the worker's function time, but my task is a long-running task. So it is limited by PHP.
I also tried to use Background Process module in order to execute my long-running task but it had the same problem as before: the execution stops at some point.
I am sure that the code can be executed completely. The only working way was through Batch page but I want to run it automatically every day (Cron).
Do you know how can I run a Cron until it finishes?
As I said, I tried with Batches and Queues but it did not work. PHP "memory exhausted" or timeout errors appear or the execution can be cut by Drupal.