fedena : rake aborted school not selected - ruby-on-rails

I was installing fedena on ubuntu installed on wsl and the database creation and migration was successful but when run the command rake fedena:plugins:install_all to install the plugins. in the middle this error pops up that school Not Selected and here is the error trace.
School Not Selected
/root/fedena/vendor/plugins/acts_as_multi_school/lib/multischool/read.rb:46:in `with_school'
/root/fedena/vendor/plugins/acts_as_multi_school/lib/multischool/read.rb:22:in `find_with_school'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.5/lib/active_record/base.rb:1954:in `find'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.5/lib/active_record/base.rb:1954:in `find_or_create_by_config_key'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.5/lib/active_record/base.rb:1940:in `send'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activerecord-2.3.5/lib/active_record/base.rb:1940:in `method_missing_without_paginate'
/root/fedena/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:170:in `method_missing'
/root/fedena/app/models/configuration.rb:90:in `find_or_create_by_config_key'
/root/fedena/db/seeds.rb:26
/root/fedena/db/seeds.rb:2:in `each'
/root/fedena/db/seeds.rb:2
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load_without_new_constant_marking'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rails-2.3.5/lib/tasks/databases.rake:215
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/root/fedena/lib/tasks/fedena_plugin_install.rake:31
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/usr/local/rvm/rubies/ruby-1.8.7-p374/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/local/rvm/gems/ruby-1.8.7-p374/gems/rake-0.8.7/bin/rake:31
/usr/local/rvm/gems/ruby-1.8.7-p374/bin/rake:19:in `load'
/usr/local/rvm/gems/ruby-1.8.7-p374/bin/rake:19
the code causing this error appears to be this code:
module MultiSchool
module Read
def self.extended (base)
eigen_class = class << base;self;end
["find","count","sum","exists?"].each do |method|
matches = method.match /([\w\d_]+)(\?|!|=)?$/
eigen_class.send :define_method, "#{matches[1]}_with_school#{matches[2]}" do |*args|
options = args.extract_options!
skip_multischool = options.delete :skip_multischool
args << options unless options.empty?
result = if skip_multischool || Thread.current[:skip_multischool].present?
send("#{matches[1]}_without_school#{matches[2]}",*args)
else
with_school do
send("#{matches[1]}_without_school#{matches[2]}",*args)
end
end
result
end
eigen_class.send :alias_method_chain, method, :school
end
end
def skip_multischool
Thread.current[:skip_multischool]=true
yield
ensure
Thread.current[:skip_multischool]=nil
end
private
def with_school
target_school = MultiSchool.current_school
if target_school.nil?
raise MultiSchool::Exceptions::SchoolNotSelected,"School Not Selected"
else
with_scope(:find => {:conditions => {:school_id => target_school.id}}) do
yield
end
end
end
end
end
looks the MultiSchool.current_school is returning nil which sets the variable target_school to nil so the above exception occurs of school not selected but I don't know where to from here?
Could you please help me out this issue.

Related

ActionMailer w/ Custom Rake Task

I am trying to create two custom rake tasks in in Rails 4 app. They are supposed to read the agent_card table and based on the logic, fire off an email when the time is triggered. This is my first time creating a rake task and I am not getting an error, therefore I don't know if I am doing it right. I would assume when using the mailer that letter opener would work once the mailer is fired (should it all be working correctly), but I am not sure. I have posted all relevant code below. Thanks in advance!
.rake file
namespace :agent_cards do
desc 'Sends an email to an agent with a license expiring 2 months from today'
task license_expire_agent: :environment do
Rails.logger.info "Mailer Method #{ActionMailer::Base.delivery_method}"
AgentCard.all.each do |agent_card|
if agent_card.real_estate_license_expires_at == Date.today + 2.months
LicenseExpireMailer.license_expire_agent(#agent_card, #agent).deliver_later
end
end
end
end
namespace :agent_cards do
desc 'Sends an email to an the agent development manager when a license expires 1 week from today'
task license_expire_mgr: :environment do
Rails.logger.info "Mailer Method #{ActionMailer::Base.delivery_method}"
AgentCard.all.each do |agent_card|
if agent_card.real_estate_license_expires_at == Date.today + 7
LicenseExpireMailer.license_expire_mgr(#agent_card, #agent).deliver_later
end
end
end
end
license_expire_agent_mailer.rb
class LicenseExpireMailer < ActionMailer::Base
default from: "Mike <help#mike.com>"
def license_expire_agent(agent, agent_card)
#agent = agent
#agent_card = agent_card
mail to: "mike#mike.com", subject: 'Your license is about to expire!'
end
end
license_expire_mgr_mailer.rb
class LicenseExpireMailer < ActionMailer::Base
default from: "Mike <help#mike.com>"
def license_expire_mgr(agent, agent_card)
#agent = agent
#agent_card = agent_card
# Head of Agent Development
mail to: "mike#mike.com", subject: "#{#agent.name}'s License Expiring"
end
end
When I try to test the rake task I enter
rake agent_cards:license_expire_agent
or
rake agent_cards:license_expire_mgr
Error
NameError: uninitialized constant LicenseExpireMailer
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:7:in `block (3 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activerecord- 4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1#global/gems/activerecord-4.2.6/lib/active_record/relation/delegation.rb:46:in `each'
/Users/michaelwiesenhart/Code/lib/tasks/license_expiration.rake:5:in `block (2 levels) in <top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:248:in `block in execute'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:243:in `execute'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:187:in `block in invoke_with_call_chain'
/Users/michaelwiesenhart/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:180:in `invoke_with_call_chain'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/task.rb:173:in `invoke'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:150:in `invoke_task'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `each'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:106:in `block in top_level'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:115:in `run_with_threads'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:100:in `top_level'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:78:in `block in run'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/lib/rake/application.rb:75:in `run'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/gems/rake-11.1.2/bin/rake:33:in `<top (required)>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/bin/rake:23:in `load'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/bin/rake:23:in `<main>'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
/Users/michaelwiesenhart/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => agent_cards:license_expire_agent
Your mailer file name does not match with the mailer class name as per Rails convention.
Mailer class should be placed in this path:
app/mailers/license_expire_mailer.rb

uninitialized constant when running rspec test with concerns used in models

When I run rspec spec/models/football_match_spec.rb I get an uninitialized constant error:
/Users/jamessmith/project/app/models/football_match.rb:3:in `<class:FootballMatch>': uninitialized constant FootballMatch::Type1Fixture (NameError)
from /Users/jamessmith/project/app/models/football_match.rb:1:in `<top (required)>'
from /Users/jamessmith/project/spec/models/football_match_spec.rb:3:in `<top (required)>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in `load'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in `each'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:97:in `setup'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:85:in `run'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:70:in `run'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/lib/rspec/core/runner.rb:38:in `invoke'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/gems/rspec-core-3.2.0/exe/rspec:4:in `<top (required)>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `load' from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/rspec:23:in `<main>'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `eval'
from /Users/jamessmith/.rvm/gems/ruby-2.1.2/bin/ruby_executable_hooks:15:in `<main>'
Type1Fixture concern:
module Type1Fixture
extend ActiveSupport::Concern
def competitors
[competitor_1, competitor_2]
end
def competitor_1_score
[fhhts || 0, shhts || 0, ethts || 0].reduce(:+)
end
def competitor_2_score
[fhats || 0, shats || 0, etats || 0].reduce(:+)
end
def name_with_scores
if [Fixture::IN_PROGRESS_STATUS, Fixture::COMPLETED_STATUS].include?(status)
"#{competitor_1.name} #{home_team_score} - #{away_team_score} #{competitor_2.name}"
else
"#{competitor_1.name} vs #{competitor_2.name}"
end
end
end
Edited FootballMatch model:
class FootballMatch < Fixture
include Mongoid::Document
include Type1Fixture
end
I've added app/models/concerns to the config.autoload_paths array in environments/test.rb.
This can be caused by not having the correct file name. For Type1Fixture, the file containing the class should be called app/models/concerns/type1_fixture.rb. Is this the case?

sunspot:reindex error - getaddrinfo: nodename nor servname provided, or not known

I'm working with a Rails 3.2 application that has a mysql database and a number of models that are being indexed in Solr.
Here's what's happening:
I am running the following command:
RAILS_ENV=development bundle exec rake sunspot:reindex[1000] --trace
After indexing about 12% of the 4 million records (although it's a different percentage every time), the process inevitably bombs out with the following error and stack trace:
rake aborted!
getaddrinfo: nodename nor servname provided, or not known
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `open'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:762:in `connect'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:744:in `start'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/net/http.rb:1284:in `request'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/connection.rb:15:in `execute'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/solr_instrumentation.rb:14:in `block in execute_with_as_instrumentation'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/solr_instrumentation.rb:12:in `execute_with_as_instrumentation'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:167:in `execute'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive'
(eval):2:in `post'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:67:in `update'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:87:in `add'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:106:in `add_documents'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:30:in `add'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session.rb:91:in `index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session_proxy/retry_5xx_session_proxy.rb:17:in `method_missing'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot.rb:184:in `index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:261:in `block (2 levels) in solr_index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:365:in `solr_benchmark'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:260:in `block in solr_index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/relation/batches.rb:72:in `find_in_batches'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/activerecord-3.2.13/lib/active_record/querying.rb:8:in `find_in_batches'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:259:in `solr_index'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:203:in `solr_reindex'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/tasks.rb:64:in `block (3 levels) in <top (required)>'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/class_set.rb:16:in `each'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/class_set.rb:16:in `each'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/tasks.rb:63:in `block (2 levels) in <top (required)>'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
/Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rake-10.0.4/bin/rake:33:in `<top (required)>'
/Users/tchapin/.rbenv/versions/1.9.3-p392/bin/rake:23:in `load'
/Users/tchapin/.rbenv/versions/1.9.3-p392/bin/rake:23:in `<main>'
The app is running in development mode at localhost:3000, and solr is running at localhost:8982. Here's my solr.rake file:
Rake::Task['sunspot:reindex'].enhance ['sunspot:scope_models_for_index']
Rake::Task['sunspot:solr:reindex'].enhance ['sunspot:scope_models_for_index']
namespace 'sunspot' do
task :scope_models_for_index => :environment do
require 'rsolr/error'
Dir.glob(Rails.root.join('app/models/**/*.rb')).each { |path| require path }
# Add the GC
commit_extension = Module.new do
def commit
GC.start
super
end
end
Sunspot.extend commit_extension
# Set all the models default scopes the index scope
Sunspot.searchable.each do |model|
model.class_eval do
default_scope ->{ sunspot_index } if model.respond_to?(:sunspot_index)
end
end
end
end
Anyone know what might be causing this error, or how to fix it?
Apparently the problem is due to an exception: SocketError.
The exception occurs in the file /Users/tchapin/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/connection.rb:
def execute client, request_context
h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout]
request = setup_raw_request request_context
request.body = request_context[:data] if request_context[:method] == :post and request_context[:data]
begin
response = h.request request
charset = response.type_params["charset"]
{:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)}
rescue Errno::ECONNREFUSED => e
raise(Errno::ECONNREFUSED.new(request_context.inspect))
# catch the undefined closed? exception -- this is a confirmed ruby bug
rescue NoMethodError
$!.message == "undefined method `closed?' for nil:NilClass" ?
raise(Errno::ECONNREFUSED.new) :
raise($!)
end
end
It's not the prettiest fix, and it's obviously not a solution for production code, but I was able to temporarily solve the problem by adding a rescue handler for the SocketError exception, like so:
def execute client, request_context
h = http request_context[:uri], request_context[:proxy], request_context[:read_timeout], request_context[:open_timeout]
request = setup_raw_request request_context
request.body = request_context[:data] if request_context[:method] == :post and request_context[:data]
retries = 10
begin
response = h.request request
charset = response.type_params["charset"]
{:status => response.code.to_i, :headers => response.to_hash, :body => force_charset(response.body, charset)}
rescue Errno::ECONNREFUSED => e
raise(Errno::ECONNREFUSED.new(request_context.inspect))
# catch the undefined closed? exception -- this is a confirmed ruby bug
rescue NoMethodError
$!.message == "undefined method `closed?' for nil:NilClass" ?
raise(Errno::ECONNREFUSED.new) :
raise($!)
rescue SocketError => e
puts e
if retries > 0
puts "SocketError! Retrying connection after 1 second..."
retries -= 1
sleep(1)
retry
else
puts "SocketError: Not responding after 10 retries! Giving up!")
exit
end
end
end
Additionally, it looks like my local copy of Solr was having some issues with running out of memory. I solved the memory problem by updating my sunspot.yml file accordingly:
development:
solr:
hostname: 127.0.0.1
port: 8982
min_memory: 512M
max_memory: 2G
log_level: INFO
# open_timeout: 3
# read_timeout: 3

How to populate devise user

I want to populate db with fake data, using faker and populator gems.
Using Devise generated a model User.
this is my rake file
namespace :db do
desc "Fill database with sample data"
task populate: :environment do
[User, Article].each(&:delete_all)
password = "password"
User.populate 20 do |user|
user.name = Faker::Name.name
user.email = Faker::Internet.email
user.password = password
user.password_confirmation = password
Article.populate 5 do |article|
article.user_id = user.id
article.title = Populator.words(1..3).titleize
article.content = Populator.sentences(2..10)
article.created_at = 2.years.ago..Time.now
end
end
end
end
When i run rake db:populate raises the following
rake aborted!
undefined method `password=' for #<Populator::Record:0xa179d14>
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/record.rb:64:in `method_missing'
/home/sunloverz/RubymineProjects/socialnews/lib/tasks/sample_date.rake:10:in `block (3 levels) in <top (required)>'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:53:in `call'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:53:in `block in build_records'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:50:in `times'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:50:in `build_records'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:43:in `block in populate'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:29:in `remember_depth'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:42:in `populate'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/model_additions.rb:25:in `populate'
/home/sunloverz/RubymineProjects/socialnews/lib/tasks/sample_date.rake:6:in `block (2 levels) in <top (required)>'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:246:in `call'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:246:in `block in execute'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:241:in `each'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:241:in `execute'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:184:in `block in invoke_with_call_chain'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:177:in `invoke_with_call_chain'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/task.rb:170:in `invoke'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:143:in `invoke_task'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:101:in `block (2 levels) in top_level'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:101:in `each'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:101:in `block in top_level'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:110:in `run_with_threads'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:95:in `top_level'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:73:in `block in run'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:160:in `standard_exception_handling'
/home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/rake-10.0.4/lib/rake/application.rb:70:in `run'
Tasks: TOP => db:populate
(See full trace by running task with --trace)
What is wrong?
Populator doesn't load the ActiveRecord instance; so any validations, callbacks, embedded methods wouldn't work. Instead it loads its own Record object, using columns attributes and pure SQL to boost performance.
On the other hand, Devise doesn't create :password column, it creates encrypted_password column and does all the logic behind the scene, check this link if you want to have insight about devise code.
Solution: We need to call password_digest to encrypt the given password, and then set the encrypted_password directly, but this method is protected and can't be called inside the rake. Instead we would use the 'new' method to trigger password_digest, so your code would be something like this:
password = "password"
User.populate 20 do |user|
user.name = Faker::Name.name
user.email = Faker::Internet.email
user.encrypted_password = User.new(:password => password).encrypted_password
# rest of your code here
end
Make sure that your Model (table in your case) actually has a column named "password".
If so, then, try to check if it has attr_accessible :password

How to resolve deserialization error in delayed job?

I am trying to use DelayedJob and the job is failing, giving the following error in the database:
{Delayed::DeserializationError
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/serialization/active_record.rb:7:in `yaml_new'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `transfer'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `node_import'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/yaml.rb:133:in `load'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/backend/base.rb:79:in `payload_object'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/backend/base.rb:87:in `invoke_job_without_newrelic_transaction_trace'
(eval):3:in `invoke_job'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.13.4/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:252:in `perform_action_with_newrelic_trace'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.13.4/lib/new_relic/agent/method_tracer.rb:141:in `trace_execution_scoped'
/Library/Ruby/Gems/1.8/gems/newrelic_rpm-2.13.4/lib/new_relic/agent/instrumentation/controller_instrumentation.rb:247:in `perform_action_with_newrelic_trace'
(eval):2:in `invoke_job'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:120:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/timeout.rb:62:in `timeout'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:120:in `run'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:119:in `run'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:177:in `reserve_and_run_one_job'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:104:in `work_off'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:103:in `times'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:103:in `work_off'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:78:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/benchmark.rb:308:in `realtime'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:77:in `start'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:74:in `loop'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/worker.rb:74:in `start'
/Library/Ruby/Gems/1.8/gems/delayed_job-2.1.3/lib/delayed/tasks.rb:9
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:636:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:597:in `invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/monitor.rb:242:in `synchronize'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2029:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2001:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/Library/Ruby/Gems/1.8/gems/rake-0.8.7/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19
Not sure where to start in diagnosing this. This has never happened before and I have used delayed job before to serialize model objects without any issues. Why this time?
Thanks in advance!
It's not really a deserialization error, it's an ActiveRecord record-not-found error on a simple Model.find(id) query.
If you want to know the details, log them in the delayed_job-2.1.3/lib/delayed/serialization/active_record.rb file, in the rescue statement, just before delayed-job stupidly raises the DeserializationError and throws the useful information away.
Michiel is right. Look at your handler field for objects like "!ruby/ActiveRecord:YourClassName"
Then check if objects can be retrieved via the primary key
From the console you can also test this out by doing something like:
# first job in your delayed queue
YAML.load(Delayed::Backend::ActiveRecord::Job.first.handler)
I believe this occurs when you run a job against an unsaved or deleted AR object since the deserialization for AR loads the record by id. An exception should probably be thrown if you attempt to delay a method on an unsaved AR object.
There's also a documented bug with DJ when the params passed into the handler field in the DB are longer than a standard TEXT column:
https://github.com/collectiveidea/delayed_job/issues/491
If this happens to be your problem, changing the column to a MEDIUMINT should fix the issue.
I did this in a migration like so:
change_column :delayed_jobs, :handler, :text, :limit => 16777215
ActiveRecord::Base.connection.execute("DELETE FROM delayed_jobs WHERE LENGTH(handler) >= 65535")
You can check to see if it's an issue with a simple DB query:
SELECT * FROM delayed_jobs WHERE LENGTH(handler) >= 65535
If anyone wants to make delayed_job just finish the job as a no-op you can monkey patch with this code in the initializer:
https://gist.github.com/spilliton/8494752
Today, I also suffered through this error and after doing hectic analysis found:
delayed_job converts methods & parameters to YAML format and stores it into database
It can be found using select * from delayed_jobs;
deserialization error occurs when delayed_job is not able to deserialize it.
Probable causes can be:
args["xyz"] used before calling delayed_job & inside worker using it as args[:xyz]
Sometimes extra arguments passed along with object to delayed_job that time delayed_job fails to build object as it is indifferent access.
I Hope this will help!
Sometimes when we upgrade libs delayed jobs still keep old references.
Try to find the id of delayed_job in logs and play to parse its handler to ruby to find the wrong reference
j = DelayedJob.find(XXX)
data = YAML.load_dj(j.handler)
data.to_ruby
I made a pull request to help with this problem.
Meanwhile you can use this lines
# config/initializers/delayed_job.rb
# Monkey patch to use old class references
module Psych
class << self; attr_accessor :old_class_references end
#old_class_references = {}
class ClassLoader
private
def find klassname
klassname = ::Psych.old_class_references[klassname] || klassname
#cache[klassname] ||= resolve(klassname)
end
end
module Visitors
class ToRuby < Psych::Visitors::Visitor
def revive klass, node
if klass.is_a? String
klassname = ::Psych.old_class_references[klass] || klass
klass = Kernel.const_get(klassname) rescue klassname
end
s = register(node, klass.allocate)
init_with(s, revive_hash({}, node), node)
end
end
end
end
# Add all old dependencies (hash keys) pointing to new references (hash values)
Psych.old_class_references = {
'ActiveRecord::AttributeSet' => 'ActiveModel::AttributeSet'
# ...
}

Resources