update startup file
This commit is contained in:
parent
80edfa528d
commit
764f4326e4
|
@ -34,8 +34,6 @@ require "action_controller/railtie"
|
|||
require "action_mailer/railtie"
|
||||
require "sprockets/railtie"
|
||||
require "rails/test_unit/railtie"
|
||||
require "mongoid"
|
||||
require "mongoid/railtie"
|
||||
require "bson"
|
||||
|
||||
require 'app/models/concerns/slug'
|
||||
|
@ -44,7 +42,11 @@ require 'app/uploaders/image_uploader'
|
|||
require 'app/models/tag'
|
||||
require 'app/models/category'
|
||||
Mongoid.load!("config/mongoid.yml")
|
||||
require 'impressionist'
|
||||
# require 'impressionist'
|
||||
orm = 'mongoid'
|
||||
require "impressionist/models/#{orm}/impression.rb"
|
||||
require "impressionist/models/#{orm}/impressionist/impressionable.rb"
|
||||
|
||||
require 'app/models/site'
|
||||
require 'app/models/page_set' #need for site save
|
||||
|
||||
|
@ -63,115 +65,7 @@ if Site.count == 0
|
|||
site.save
|
||||
end
|
||||
begin
|
||||
require 'process_shared'
|
||||
class ProcesssShareWraper
|
||||
attr_accessor :data
|
||||
attr_accessor :need_process
|
||||
def parse_value(v)
|
||||
if v[0] == String
|
||||
v[1].read_string.force_encoding('utf-8')
|
||||
elsif v[0] == Fixnum
|
||||
v[1].read_int64
|
||||
elsif v[0] == Float
|
||||
v[1].read_float
|
||||
else
|
||||
v[1].read_object
|
||||
end
|
||||
end
|
||||
def save_value(h,v)
|
||||
if h[0] == String
|
||||
h[1].write_string(v)
|
||||
elsif h[0] == Fixnum
|
||||
h[1].write_int64(v)
|
||||
elsif h[0] == Float
|
||||
h[1].write_float(v)
|
||||
else
|
||||
tmp_obj = Marshal.dump(v)
|
||||
if tmp_obj.bytesize > h[1].size
|
||||
puts "#{v.class}: out of memory"
|
||||
puts v
|
||||
puts "-------------------------------"
|
||||
else
|
||||
begin
|
||||
h[1].write_string(tmp_obj)
|
||||
rescue => e
|
||||
puts "#{v.class}: #{e.to_s}"
|
||||
puts v
|
||||
puts "-------------------------------"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(data)
|
||||
self.need_process = true
|
||||
def process_value(v)
|
||||
case v
|
||||
when String
|
||||
str_len = v.bytesize * 2
|
||||
str_len = 250 if str_len < 250
|
||||
tmp = ProcessShared::SharedMemory.new(:uint8, str_len)
|
||||
tmp.write_string(v)
|
||||
[String,tmp]
|
||||
when Fixnum
|
||||
tmp = ProcessShared::SharedMemory.new(:int64)
|
||||
tmp.write_int64(v)
|
||||
[Fixnum,tmp]
|
||||
when Float
|
||||
tmp = ProcessShared::SharedMemory.new(:float)
|
||||
tmp.write_float(v)
|
||||
[Float,tmp]
|
||||
else
|
||||
tmp_obj = Marshal.dump(v)
|
||||
size = tmp_obj.bytesize*2
|
||||
if v.respond_to?(:min_memory)
|
||||
size = [size, v.min_memory].max
|
||||
else
|
||||
size = [size, 1000].max
|
||||
end
|
||||
tmp = ProcessShared::SharedMemory.new(:uint8, size)
|
||||
tmp.write_string(tmp_obj)
|
||||
[Object,tmp]
|
||||
end
|
||||
end
|
||||
case data
|
||||
when Hash
|
||||
self.data = data.map do |k,v|
|
||||
[k,process_value(v)]
|
||||
end.to_h
|
||||
when Array
|
||||
self.data = data.map{|v| process_value(v)}
|
||||
else
|
||||
self.need_process = false
|
||||
self.data = process_value(data)
|
||||
end
|
||||
end
|
||||
def value
|
||||
if self.need_process
|
||||
case self.data
|
||||
when Hash
|
||||
self.data.map{|k,v| [k,parse_value(v)]}.to_h
|
||||
when Array
|
||||
self.data.map{|v| parse_value(v)}
|
||||
end
|
||||
else
|
||||
parse_value(self.data)
|
||||
end
|
||||
end
|
||||
def value=(v)
|
||||
if self.need_process
|
||||
raise 'You cannot change value.'
|
||||
else
|
||||
save_value(self.data,v)
|
||||
end
|
||||
end
|
||||
def [](k)
|
||||
parse_value(self.data[k])
|
||||
end
|
||||
def []=(k,v)
|
||||
save_value(self.data[k],v)
|
||||
end
|
||||
end
|
||||
require 'config/process_share_wrapper'
|
||||
@mutex = ProcessShared::Mutex.new
|
||||
@shared_hash = {}
|
||||
orbit_gem_specs.each do |v|
|
||||
|
@ -180,14 +74,36 @@ begin
|
|||
tmp = tmp ? eval(tmp) : nil
|
||||
gem_name = v.name
|
||||
if tmp
|
||||
@shared_hash[gem_name] = ProcesssShareWraper.new(tmp)
|
||||
@shared_hash[gem_name] = ProcessShareWrapper.new(tmp)
|
||||
end
|
||||
end
|
||||
s = Site.first
|
||||
@shared_hash['current_site'] = ProcesssShareWraper.new({"site"=> s})
|
||||
@shared_hash['privileged_page_count'] = ProcesssShareWraper.new((s.privileged_page_count rescue 0))
|
||||
@shared_hash['current_site'] = ProcessShareWrapper.new({"site"=> s})
|
||||
@shared_hash['privileged_page_count'] = ProcessShareWrapper.new((s.privileged_page_count rescue 0))
|
||||
Thread.current[:shared_hash] = @shared_hash
|
||||
Thread.current[:shared_mutex] = @mutex
|
||||
rescue LoadError => e
|
||||
env_pwd = ENV['PWD']
|
||||
begin
|
||||
require ::File.expand_path('app/helpers/bundler_helper.rb', env_pwd)
|
||||
include BundlerHelper
|
||||
rescue LoadError
|
||||
def bundler_with_clean_env(&block)
|
||||
if block_given?
|
||||
if Bundler.respond_to?(:with_unbundled_env)
|
||||
Bundler.with_unbundled_env(&block)
|
||||
else
|
||||
Bundler.with_clean_env(&block)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
reset_paths = ["config/application.rb", "config/unicorn.rb", "config/set_global_variable.rb", "config/process_share_wrapper.rb", "lib/orbit_app", "lib/orbit_core_lib.rb"]
|
||||
all_command = reset_paths.map do |reset_path|
|
||||
"git clean -f -- #{reset_path} && git reset origin -- #{reset_path} && git checkout -- #{reset_path}"
|
||||
end.join('&&')
|
||||
bundler_with_clean_env do
|
||||
system("cd #{env_pwd} && #{all_command}")
|
||||
end
|
||||
puts ['error in unicorn',e,e.backtrace]
|
||||
end
|
Loading…
Reference in New Issue