A 524 error indicates a timeout after establishing a TCP connection and waiting for a response from your origin.
Meaning Cloudflare connected to your webserver successfully but didn’t receive a response within 100 second - this is how long Cloudflare will wait for a response from your webserver and if none is received, it will close a connection and return a 524 error.
This can happen if your server is simply taking too long because it has too much work to do - e.g. a large data query, or because the server is struggling for resources and cannot return any data in time. Implementing status polling of large HTTP processes can help to avoid the error.
Or you can run the scripts via a grey-clouded subdomain (bypassing Cloudflare)