I've created a class that extends DailyTask to use for a cron job. What the task does is download several large files from a government bureau and insert those csv files into temp tables. Each function in the class works correctly, however, when I run them all together I start gettings errors saying "MySQL server has gone away." on simple DB::query() calls using insert statements. If, however, I remove the function to download the files (and manually upload the files to the proper directory), it executes without a problem and actually inserts the data into the temp tables.
From what I have been able to find online, the MySQL error is most often caused by a timeout. Is there a way to delay the Silverstripe database connection until right before it's needed to allow the files to be downloaded from the remote FTP first? Or should I close the connection and reopen it right before needing it?
I've attached a screenshot of my shell window when running the task with Sake. Any insight would be greatly appreciated.