Ruby on Rails can take a long time to boot so in some cases it can be useful to provide some kind of progress reporting (f.x. if you are considering using Rails in an embedded application).
RoR does not provide any direct means to monitoring the progress of the boot-process, so a little work is necessary. Changing the ruby source files involved in the boot process is not ideal from a maintenance standpoint and even if one does so, the progress report turns out to be very uneven. The best approach I could come up with was a Kernel hook which keeps track of when files are require‘d. Both easy to do and works surprisingly well for fine-tuned progress reporting.
# Hook into require so that we can track startup progress module Kernel alias org_untracked_require_myAppName require def require(file, *extras) v=org_untracked_require_myAppName(file, *extras) $progress_coordinator.addWorkDelta(1,'Rails required '+file.to_s) unless progress_coordinator.nil? || file.nil? || !v v end end
Advertisement