Last active
December 5, 2017 17:12
-
-
Save michaeldever/7457788d61807e77704e99d057fba395 to your computer and use it in GitHub Desktop.
Basic Setup
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
#!/usr/bin/env ruby | |
ENV['RAILS_ENV'] ||= 'development' | |
require_relative '../config/environment' | |
def files_to_reopen | |
@files_to_reopen ||= [] | |
end | |
def collect_open_files | |
# NOTE: Logging fix for daemons under Rails | |
ObjectSpace.each_object(File) do |file| | |
files_to_reopen << file unless file.closed? | |
end | |
end | |
def reopen_initial_files | |
# NOTE: Logging fix for daemons under Rails | |
files_to_reopen.each do |file| | |
file.reopen file.path, 'a+' | |
file.sync = true | |
end | |
end | |
def establish_active_record_connection | |
defined?(ActiveRecord::Base) && ActiveRecord::Base.establish_connection | |
end | |
collect_open_files | |
Daemons.run_proc('rabbit_mq', multiple: false, backtrace: true, log_output: true) do | |
begin | |
establish_active_record_connection | |
reopen_initial_files | |
rescue StandardError => e | |
puts e.message | |
puts e.backtrace | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment