Created
July 25, 2016 13:22
-
-
Save flarik/9b0a8b323a74e07a0eb97bd0de0a7d1e to your computer and use it in GitHub Desktop.
Reopen closed file descriptors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/collectiveidea/delayed_job/blob/ce88693429188a63793b16daaab67056a4e4e0bf/lib/delayed/worker.rb#L77 | |
def files_to_reopen | |
unless @files_to_reopen | |
@files_to_reopen = [] | |
ObjectSpace.each_object(File) do |file| | |
@files_to_reopen << file unless file.closed? | |
end | |
end | |
@files_to_reopen | |
end | |
def reopen_files | |
@files_to_reopen.each do |file| | |
begin | |
puts "reopening: #{file}" | |
file.reopen file.path, 'a+' | |
file.sync = true | |
rescue ::Exception => e # rubocop:disable HandleExceptions, RescueException | |
puts "oepsie, raise...", e | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment