Thin fails spawning workers when running on EventMachine - ruby

I have a ruby web- / data-server application which is built on a Sinatra foundation. I'm adding EventMachine and em-websocket so that I can have async data transfer connections.
#! /usr/bin/env ruby
require 'yajl'
require 'json'
require 'em-websocket'
require 'sinatra/base'
require 'thin'
require './Actors/DataProvider.rb'
my_host = '10.2.56.87'
my_web_port = '4004'
my_web_sock = '8008'
EventMachine.epoll # choose kernel epoll over select for deterministic execution under load
EventMachine.run do
class SinatraApp < Sinatra::Base
configure do
set :bind, '10.2.56.87'
set :port, '4004'
end
encoder = Yajl::Encoder.new
communicator = DataProvider.new( encoder )
get '/' do
redirect '/index-work.html'
end
before do
content_type 'application/json'
end
post '/auth' do
end
post '/data/:id' do
puts 'got d i '
end
end
EventMachine::WebSocket.start( :host => my_host, :port => my_web_sock ) do | ws |
ws.onopen do
end
ws.onmessage do
end
ws.onclose do
end
end
begin
SinatraApp.run!
rescue => ex
puts "#{ ex.class}: #{ ex.message }"
end
end
The Thin server worked fine when just serving Sinatra, but now that I've added the EM foundation the following occurs:
/usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:192:in `block (2 levels) in start': undefined method `attach_server' for EventMachine:Module (NoMethodError)
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `each'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:191:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:30:in `block (2 levels) in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:23:in `block in start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker/worker.rb:52:in `work'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:129:in `block (2 levels) in spawn_missing_workers'
from (eval):6:in `block in fork'
from (eval):6:in `fork'
from (eval):6:in `fork'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:126:in `block in spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `times'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:124:in `spawn_missing_workers'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/preforker-0.1.1/lib/preforker.rb:44:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/backends/prefork.rb:37:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/thin-2.0.0.pre/lib/thin/server.rb:187:in `start'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/handler/thin.rb:13:in `run'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/sinatra-1.3.3/lib/sinatra/base.rb:1350:in `run!'
from /home/devel/ISF_Server/server-work.rb:122:in `block in <top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `call'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run_machine'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/eventmachine-1.0.0/lib/eventmachine.rb:187:in `run'
from /home/devel/ISF_Server/server-work.rb:15:in `<top (required)>'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_load'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/lib/ruby-debug-ide.rb:127:in `debug_program'
from /usr/local/rvm/gems/ruby-1.9.3-p286/gems/ruby-debug-ide-0.4.17.beta14/bin/rdebug-ide:118:in `<top (required)>'
from -e:1:in `load'
from -e:1:in `<main>'
I do notice that the Thin gem was recently updated, but EM has not been. That's my next point of inquiry. Somebody else posted that Thin should not be run from within EM.run block, but the example I am building from had it this way.

Okay. I corresponded with Marc-Andre Cournoyer directly. He says, first, don't spawn This (through Sinatra) inside an EM.run block.
Secondly, the error is generated from Thin 2 (pre) which requires the EventMachine live Edition, or gem eventmachine-le.
Mo' bettah now. :D

Related

undefined method `rescue_responses' for ActionDispatch::ShowExceptions:Class (NoMethodError)

In my ruby 2.3.1, I get this error:
=> Booting WEBrick
=> Rails 4.2.6 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/will_paginate-3.0.pre2/lib/will_paginate/railtie.rb:15:in `block in <class:Railtie>': uninitialized constant WillPaginate::Railtie::Forbidden (NameError)
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `instance_exec'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:30:in `run'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:55:in `block in run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `call'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/initializable.rb:54:in `run_initializers'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/application.rb:352:in `initialize!'
from /home/bistipweb/config/environment.rb:5:in `<top (required)>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/polyglot-0.3.1/lib/polyglot.rb:64:in `require'
from /home/bistipweb/config.ru:3:in `block in <main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `instance_eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:55:in `initialize'
from /home/bistipweb/config.ru:in `new'
from /home/bistipweb/config.ru:in `<main>'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `eval'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:49:in `new_from_string'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/builder.rb:40:in `parse_file'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:299:in `build_app_and_options_from_config'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:208:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:61:in `app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rack-1.6.0/lib/rack/server.rb:336:in `wrapped_app'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:139:in `log_to_stdout'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/server.rb:78:in `start'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:80:in `block in server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /root/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
My railtie.rb is:
require 'will_paginate'
require 'will_paginate/collection'
module WillPaginate
class Railtie < Rails::Railtie
initializer "will_paginate.active_record" do |app|
if defined? ::ActiveRecord
require 'will_paginate/finders/active_record'
WillPaginate::Finders::ActiveRecord.enable!
end
end
initializer "will_paginate.action_dispatch" do |app|
if defined?(ActionController::Base)
config.action_dispatch.rescue_responses.update('ActionController::Forbidden'=>Forbidden)
end
end
initializer "will_paginate.action_view" do |app|
require 'will_paginate/view_helpers/action_view'
ActionView::Base.send(:include, WillPaginate::ViewHelpers::ActionView)
end
end
end
How can I fix it?
You don't have to add any initializer codes for hooking will_paginate into Rails project, if you are using recent will_paginate versions.
I see you are using 3.0.pre2 version, update it to 3.0.7 in your Gemfile, bundle update will_paginate and remove all the codes you added in railtie.rb, I think everything would be ok.
Try:
initializer "will_paginate.action_dispatch" do |app|
if defined?(ActionController::Base)
config.action_dispatch.rescue_responses.update('ActionController::Forbidden'=>Forbidden)
end
end
I do not find any reason for you to add railtie.rb file. I believe just adding the gem and using it in your view should work.

How to check whether a function exist in ruby and also with parameter

My Ruby file
require 'puppet'
# ...
require 'googleauth'
module PuppetX
module Puppetlabs
module Google_cloud_dns
class Provider < PuppetX::Puppetlabs::Swagger::Provider
def client
self.class.client
end
My RSpec file
I am using this two alternatively, but none of them working:
require_relative'../../lib/puppet_x/puppetlabs/google_cloud_dns/provider'
File.expand_path("../../lib/puppet_x/puppetlabs/google_cloud_dns/provider.rb",File.dirname(__FILE__)))
require 'spec_helper'
require_relative '../../lib/puppet_x/puppetlabs/google_cloud_dns/provider'
File.expand_path("../../lib/puppet_x/puppetlabs/google_cloud_dns/provider.rb", File.dirname(__FILE__))
describe Provider do
it "checks function" do
provide = Provider.new
provide.should respond_to :client
end
end
The error which I am getting
rspec Mymodule/gc_dns/puppet-google_cloud_dns/spec/classes/provider_spec.rb --format documentation/home/vivekkumarmishra17/Mymodule/gc_dns/puppet-google_cloud_dns/spec/classes/provider_spec.rb:19:in `<top (required)>': uninitialized constant Provider (NameError)
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `each'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in `setup'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in `invoke'
from /var/lib/gems/1.9.1/gems/rspec-core-3.4.4/exe/rspec:4:in `<top (required)>'
from /usr/local/bin/rspec:23:in `load'
from /usr/local/bin/rspec:23:in `<main>'
Can anyone tell what I am doing wrong?

Monkey patching Object leads to Pry deadlock

I'm trying to monkey patch Object and while my tests run fine,
I can't load my project with Pry anymore.
Here is the relevant code:
module CoreExtensions
def instance_values
instance_variables.each_with_object({}) do |var, hash|
hash[var[1..-1]] = instance_variable_get(var)
end
end
def ==(other)
(self.class == other.class) &&
(instance_values.equal? other.instance_values)
end
end
Object.include CoreExtensions
Using
pry -r ./core_extentions.rb
leads to this stacktrace:
Error: No live threads left. Deadlock?
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:87:in `sleep'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:87:in `wait'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:87:in `block in enter_interruptible_region'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:83:in `synchronize'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:83:in `enter_interruptible_region'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:110:in `interruptible_region'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:197:in `input_readline'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:190:in `block in read_line'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:129:in `handle_read_errors'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:170:in `read_line'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:98:in `read'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:68:in `block in repl'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:67:in `loop'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:67:in `repl'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:38:in `block in start'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:61:in `__with_ownership'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/input_lock.rb:79:in `with_ownership'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:38:in `start'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/repl.rb:15:in `start'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/pry_class.rb:169:in `start'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-byebug-3.3.0/lib/pry-byebug/pry_ext.rb:11:in `start_with_pry_byebug'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/cli.rb:219:in `block in <top (required)>'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/cli.rb:83:in `block in parse_options'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/cli.rb:83:in `each'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/lib/pry/cli.rb:83:in `parse_options'
/home/fap/.rvm/gems/ruby-2.3.0/gems/pry-0.10.3/bin/pry:16:in `<top (required)>' /home/fap/.rvm/gems/ruby-2.3.0/bin/pry:23:in `load'
/home/fap/.rvm/gems/ruby-2.3.0/bin/pry:23:in main
/home/fap/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/home/fap/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in main
The same thing happens when I include my CoreExtentions in the main class.
I read about Pry's input_lock, but I don't understand what produces the deadlock.
Does anyone have an idea why this is happening?
You have redefined method == for all objects, which is not a good thing.
This comes about from the last line in your question, namely Object.include CoreExtentions
Without that definition, it loads fine.

uninitialized constant ActionDispatch (NameError) in Ruby

My Code in ruby class is. Here i am getting uninitialized constant ActionDispatch (NameError)
DatabaseCleaner.strategy = :transaction
class ActionDispatch::IntegrationTest
# Make the Capybara DSL available in all integration tests
include Capybara::DSL
# Stop ActiveRecord from wrapping tests in transactions
self.use_transactional_fixtures = false
teardown do
DatabaseCleaner.clean # Truncate the database
Capybara.reset_sessions! # Forget the (simulated) browser state
Capybara.use_default_driver
end
end
I ran into the same issue, after upgrading.
This is my stack trace:
uninitialized constant ActionDispatch::IntegrationTest (NameError)
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-rails-1.3.1/lib/cucumber/rails/world.rb:9:in `<module:Rails>'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-rails-1.3.1/lib/cucumber/rails/world.rb:8:in `<module:Cucumber>'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-rails-1.3.1/lib/cucumber/rails/world.rb:7:in `<top (required)>'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/backports-3.3.0/lib/backports/tools.rb:328:in `require'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/backports-3.3.0/lib/backports/tools.rb:328:in `require_with_backports'
/Users/etagwerker/Projects/om/features/support/env.rb:11:in `<top (required)>'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/rb_support/rb_language.rb:122:in `load'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/rb_support/rb_language.rb:122:in `load_code_file'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/runtime/support_code.rb:180:in `load_file'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/runtime/support_code.rb:83:in `block in load_files!'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/runtime/support_code.rb:82:in `each'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/runtime/support_code.rb:82:in `load_files!'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/runtime.rb:183:in `load_step_definitions'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/runtime.rb:42:in `run!'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/lib/cucumber/cli/main.rb:47:in `execute!'
/Users/etagwerker/.rvm/gems/ruby-1.9.3-p327#ombu/gems/cucumber-1.3.1/bin/cucumber:13:in `<top (required)>'
script/cucumber:9:in `load'
script/cucumber:9:in `<main>'
I am using rails 3.0.20 and cucumber-rails 1.3.1.
After trying a few things, I tried this:
rails generate cucumber:install
That solved it for me.

'rescue in rbuf_fill': Timeout::Error (Timeout::Error)

Same script different error. This might be related more to my network instead of my code. The script is as follows:
#!/usr/bin/env ruby -rubygems
require File.join(File.dirname(__FILE__), 'authentication')
require "csv" # faster_csv (ruby 1.9)
lines = CSV.read(File.join(File.dirname(__FILE__), 'karaoke.csv')) # Exported an Excel file as CSV
lines.slice!(0) # remove header line
collection = StorageRoom::Collection.find('collection ID')
Song = collection.entry_class
lines.each do |row|
karaoke = Song.new(:artist => row[0], :song => row[1], :genre => row[2], :file => StorageRoom::File.new_with_filename("#{karaoke.artist}#{karaoke.song}.mov"))
if karaoke.save
puts "Song saved: #{karaoke.artist}, #{karaoke.song}, #{karaoke.genre}"
else
puts "Song could not be saved: #{karaoke.errors.join(', ')}"
end
end
And the error is:
/usr/local/lib/ruby/1.9.1/net/protocol.rb:140:in `rescue in rbuf_fill': Timeout::Error (Timeout::Error)
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:134:in `rbuf_fill'
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:116:in `readuntil'
from /usr/local/lib/ruby/1.9.1/net/protocol.rb:126:in `readline'
from /usr/local/lib/ruby/1.9.1/net/http.rb:2219:in `read_status_line'
from /usr/local/lib/ruby/1.9.1/net/http.rb:2208:in `read_new'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1191:in `transport_request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1177:in `request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1170:in `block in request'
from /usr/local/lib/ruby/1.9.1/net/http.rb:627:in `start'
from /usr/local/lib/ruby/1.9.1/net/http.rb:1168:in `request'
from /usr/local/lib/ruby/gems/1.9.1/gems/httparty-0.8.1/lib/httparty/request.rb:73:in `perform'
from /usr/local/lib/ruby/gems/1.9.1/gems/httparty-0.8.1/lib/httparty.rb:391:in `perform_request'
from /usr/local/lib/ruby/gems/1.9.1/gems/httparty-0.8.1/lib/httparty.rb:359:in `post'
from /home/hanleyhansen/Desktop/thriventures-storage_room_gem-f7015ed/lib/storage_room/model.rb:69:in `block (2 levels) in create'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:403:in `_run__3801264735883484179__create__2558870880708463764__callbacks'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_create_callbacks'
from /home/hanleyhansen/Desktop/thriventures-storage_room_gem-f7015ed/lib/storage_room/model.rb:68:in `block in create'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:403:in `_run__3801264735883484179__save__2558870880708463764__callbacks'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:405:in `__run_callback'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.2.2/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
from /home/hanleyhansen/Desktop/thriventures-storage_room_gem-f7015ed/lib/storage_room/model.rb:67:in `create'
from /home/hanleyhansen/Desktop/thriventures-storage_room_gem-f7015ed/lib/storage_room/model.rb:61:in `save'
from import_csv.rb:17:in `block in <main>'
from import_csv.rb:14:in `each'
from import_csv.rb:14:in `<main>'
I'm interested in learning why this error occurred as well as the solution. Thanks in advance!
Found this while perusing the web. Hopes it helps somebody! Setting a longer timeout
Here is how you can adjust the timeout in the Net::HTTP API:
require 'net/http'
http = Net::HTTP.new(#host, #port)
http.read_timeout = 500

Resources