I have a rake task that requires several hours to run. I logged into my server, ran there the rake task and watched the outputs generated inside the terminal window.
Then my internet connection broke. Is there now a way to see the live output of the rake task?
Try the following:
- Find the PID of your running rake command
- Attach terminal to the last logs of the output of that process
tail -f /proc/{PID}/fd/1
. Alternatively can try to usemore
command instead oftail
Next time you could start a rake task in a session of such utils as tmux
and screen
, this way your terminal session would be stored even after connection break.
Alternatively, you could write your rake task output to a file (you can configure Rails.logger
to do it)
Instead of a Rake task, I would suggest using one or even multiple Sidekiq jobs (or whatever tools you are using to run background jobs).
Such tools are well integrated into your application monitoring and logging tools by default, and often even have a web UI that allows tracking progress of an individual job.
Plus: Engineers usually are more experienced writing tests for background jobs than testing Rake tasks.