2014-04-06 89 views
2

我使用Spree的Rails有非常奇怪的问题。Rails处理每个请求两次

每个请求正在处理两次。 AJAX没有问题,因为单个CURL请求也会被处理两次。日志也不是问题,因为行为确实发生了两次。

问题仅存在于Heroku和本地的生产环境中。

实例日志:

2014-04-06T06:45:48.969394+00:00 heroku[router]: at=info method=POST path=/spree/api/orders/R657018514/line_items host=xxx.xxx.com request_id=75ac3584-f33e-48fe-b6ce-d898120f8b57 fwd="185.12.21.77" dyno=web.1 connect=0ms service=399ms status=201 bytes=1097 
2014-04-06T06:45:48.952672+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/bundler/gems/spree-78f129b6d6f5/api/app/views/spree/api/orders/show.v1.rabl (120.9ms) 
2014-04-06T06:45:48.959453+00:00 app[web.1]: Completed 201 Created in 381ms (Views: 93.4ms | ActiveRecord: 188.8ms) 
2014-04-06T06:45:48.959460+00:00 app[web.1]: Completed 201 Created in 381ms (Views: 93.4ms | ActiveRecord: 188.8ms) 
2014-04-06T06:45:48.958355+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.0.0/bundler/gems/spree-78f129b6d6f5/api/app/views/spree/api/orders/show.v1.rabl (120.9ms) 

Started GET "/" for 127.0.0.1 at 2014-04-06 08:55:29 +0200 
Started GET "/" for 127.0.0.1 at 2014-04-06 08:55:29 +0200 
Processing by Spree::HomeController#index as HTML 
Processing by Spree::HomeController#index as HTML 
    Rendered spree/home/index.html.erb within spree/layouts/spree_application (0.8ms) 
    Rendered spree/home/index.html.erb within spree/layouts/spree_application (0.8ms) 

Gemfile.rb:

source 'https://rubygems.org' 

gem 'rails', '4.0.3' 

gem 'newrelic_rpm' 

group :assets do 
    gem 'sass-rails', '~> 4.0.0' 
    gem 'coffee-rails', '~> 4.0.0' 
    gem 'compass',      '= 0.12.2' 
    gem 'compass-rails',    '~> 1.1.2' 
    gem 'uglifier', '>= 1.0.3' 
end 

group :development do 
    gem 'sqlite3' 
    gem 'pry-rails' 
end 

group :production do 
    gem 'pg' 
    gem 'rails_12factor' 
end 

gem 'jquery-rails', '~> 3.1.0' 
gem 'jquery-ui-rails' 

gem 'handlebars_assets' 

gem 'spree', :github => "methyl/spree", :require => false 
gem 'spree_auth_devise', github: 'spree/spree_auth_devise' 

production.rb

Aimer::Application.configure do 
    # Settings specified here will take precedence over those in config/application.rb 

    # Code is not reloaded between requests 
    config.cache_classes = true 

    # Full error reports are disabled and caching is turned on 
    config.consider_all_requests_local  = false 
    config.action_controller.perform_caching = true 

    # Disable Rails's static asset server (Apache or nginx will already do this) 
    config.serve_static_assets = true 
    config.static_cache_control = "public, max-age=31536000" 

    # Compress JavaScripts and CSS 
    config.assets.compress = true 

    # Don't fallback to assets pipeline if a precompiled asset is missed 
    config.assets.compile = true 

    # Generate digests for assets URLs 
    config.assets.digest = true 

    config.assets.js_compressor = :uglifier 
    config.assets.css_compressor = :sass 

    # Defaults to nil and saved in location specified by config.assets.prefix 
    # config.assets.manifest = YOUR_PATH 

    # Specifies the header that your server uses for sending files 
    # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
    # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

    # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 
    config.force_ssl = false 

    # See everything in the log (default is :info) 
    # config.log_level = :debug 

    # Prepend all log lines with the following tags 
    # config.log_tags = [ :subdomain, :uuid ] 

    # Use a different logger for distributed setups 
    # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 

    # Use a different cache store in production 
    # config.cache_store = :mem_cache_store 

    # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) 
    # config.assets.precompile += %w(search.js) 

    # Disable delivery errors, bad email addresses will be ignored 
    # config.action_mailer.raise_delivery_errors = false 

    # Enable threaded mode 
    # config.threadsafe! 

    # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 
    # the I18n.default_locale when a translation can not be found) 
    config.i18n.fallbacks = true 

    # Send deprecation notices to registered listeners 
    config.active_support.deprecation = :notify 

    # Log the query plan for queries taking more than this (works 
    # with SQLite, MySQL, and PostgreSQL) 
    # config.active_record.auto_explain_threshold_in_seconds = 0.5 
end 
+1

你怎么知道这不是日志?我发现有两个请求具有完全相同的渲染时间是非常不可能的,对于所有请求,情况如何? – Giannis

+0

我收到两次电子邮件,AFAIK它是为每个请求。 – methyl

+0

不仅日志条目显示*确切*相同的处理时间,其中两个已在7微秒内写入对方。无论问题是什么,所显示的代码都不会涵盖它。我可能会怀疑偶然的对某些中间件组件的双重调用,可能是因为注册了两次。 –

回答

1

@Giannis,你是对的,原木只复制,原因双电子邮件在其他地方,可能在Sendgrid配置。

1

可能您之前使用过heroku进行部署,后来您开始使用任何其他实例进行部署。

尝试评论gem 'rails_12factor'一次,并进行捆绑安装,然后检查一次。