2

Ruby/Sinatra アプリケーションを提供するために、シン Web サーバーを使用しています。私の注意を引いたのは、私が実行したときです:

RACK_ENV=production rackup

すべてのリクエストは 5 回のようにログに記録され、タイムスタンプが異なります。

vagrant@lucid32:/app$ RACK_ENV=production rackup
** Building /assets/application.js...
** Building /assets/screen.css...
>> Thin web server (v1.4.1 codename Chromeo)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0024
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0034
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0044
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0054
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0065
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0076
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 4 0.0094
10.0.2.2 - - [12/Aug/2012 03:54:56] "GET / HTTP/1.1" 200 - 0.0102

それは、どういうわけかリクエストが数回行われると私に信じさせます。それとも、何度もログに記録していますか?

私がちょうど走るとき

rackup

そして、同じリクエストを試してください。これは私が代わりに得るものです。

vagrant@lucid32:/app$ rackup
>> Thin web server (v1.4.1 codename Chromeo)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:9292, CTRL+C to stop
10.0.2.2 - - [12/Aug/2012 03:56:42] "GET / HTTP/1.1" 200 - 0.1228

相違点は、基本的にはステータス コードの後の "-" であり、運用サーバーの最終ログ行と同様です。しかし、それが何を意味するのかよくわかりません。

何らかの形で本番環境でリクエストが何度も処理されるかどうかを知りたいです。私はこのルートで、このようにシナトラを使用しています。

class Project::Base < Sinatra::Application
  ..configs here
end

class Project::Routes::Home < Project::Base
  get '/'
    "something"
  end
end

config.ru

RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined? RACK_ENV
require 'sprockets'
map '/assets' do
  environment = Sprockets::Environment.new
  environment.append_path 'app/assets/javascripts'
  environment.append_path 'app/assets/stylesheets'

  run environment
end
require File.dirname(__FILE__) + '/config/boot.rb'
use Rack::Deflater
run GRBTV::Main

./config/boot.rb

require 'rubygems'
gem 'psych'

# Require default environment config
require File.join(File.dirname(__FILE__), 'env')

# Bundler setup check 
require 'bundler'
begin
  Bundler.setup
rescue Bundler::BundlerError => e
  $stderr.puts e.message
  $stderr.puts "Run 'bundle install' to install missing gems"
  exit e.status_code
end


# Sinatra
require 'sinatra/base'
require 'sinatra/flash'
require 'json'

RACK_ENV = ENV['RACK_ENV'] ||= 'development' unless defined? RACK_ENV
ROOT_DIR = File.dirname(__FILE__).gsub(/config/,'')  unless defined? ROOT_DIR

# Path helper methods 
# root_path("config", "settings.yml")
def root_path(*args)
  File.join(ROOT_DIR, *args)
end

# relative_from_root_path("~/projects/project_name/config/settings.yml") #=> "config/settings.yml"
def relative_from_root_path(path)
  Pathname.new(path).relative_path_from(Pathname.new(ROOT_DIR)).to_s
end

# public_path("images") #=> "public/images"
def public_path(*args)
  root_path('public', *args)
end

# Module containers for autoloaded helpers and routes
module GRBTV
  module Helpers
  end
  module Routes
  end
end

# Attempts to require all dependencies with bundler, if this fails, bundle and then try again
require 'bundler'
Bundler.setup(:default)
Bundler.require(:default)

# Dependencies contains all required gems and core configuration
require root_path('config', 'dependencies.rb')

def app() GRBTV::Main end

./config/dependencies.rb

require File.join(File.dirname(__FILE__), './loader')

initializers = []
# Requires initializers
Loader.load_files('config/initializers/*.rb') do |file|
  require file
  begin
    # Save Initializer module in the initializers array
    file_class = File.basename(file, '.rb').camelize
    initializers << "#{file_class}Initializer".constantize
  rescue NameError
  end
end

require 'yaml'
YAML::ENGINE.yamler = 'psych'

# Load app components
['lib/*.rb', 'app/uploaders/*.rb', 'app/models/*.rb'].each do |glob|
  Loader.load_files(glob)
end


# Basic Sinatra::Application settingss
class GRBTV::Base < Sinatra::Application
  def options() settings end

  set :root, root_path
  set :views, root_path('app', 'views')
  set :public_folder, root_path('public')
  set :environment, RACK_ENV.to_sym if defined? RACK_ENV
    set :protection, :except => :frame_options

  use Rack::MethodOverride
  enable :sessions
  register Sinatra::NamedRoutes
  register MongoMapper
  helpers Sinatra::FieldBuilder
  helpers Sinatra::Warden::Helpers

  # Require all helpers
  Loader.load_files("app/helpers/**/*.rb") do |file|
    relative_path = relative_from_root_path(file).gsub(/\.rb$/, '').gsub('app/helpers/', '')
    module_name = "GRBTV::Helpers::#{relative_path.camelize}"
    Loader.define_namespaces(module_name)
    require file
    helpers module_name.constantize
  end


  # Sets the default layout for every route
  before do
    @default_layout = :'layout'
  end

  before '/assets/*' do
    headers['Cache-Control'] = 'public, max-age=86400'
  end
end

# Load mailers
Loader.load_files('app/mailers/*.rb')


class GRBTV::Main < GRBTV::Base
  # Requiring routes after extending path helpers
  Loader.load_files("app/routes/**/*.rb") do |file|
    relative_path= relative_from_root_path(file).gsub(/\.rb$/, '').gsub('app/routes/', '')
    module_name = "GRBTV::Routes::#{relative_path.camelize}"
    Loader.define_namespaces(module_name)
    require file
    use module_name.constantize
  end
end

# Load all initializers after setup is done
initializers.each do |initializer|
  GRBTV::Base.register initializer
end
4

1 に答える 1

0

これは Sinatra/Thin のバグであり、Sinatra 1.3.3 (昨日リリース) で修正する必要があります。

于 2012-08-20T10:38:36.187 に答える