I was running tests using spork with no problem, however, occasionally I have to restart the spork server to get it to recognize newly added routes. On this occasion, I restarted the spork server, and I am now getting the following error message whenever I run any tests:
Exception encountered: #<NoMethodError: undefined method `instantiate_observers' for ActiveRecord::Base:Class>
backtrace:
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/activerecord-4.0.0/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
/Users/mydocs/Documents/rails_projects/sample_app_rails_4/spec/spec_helper.rb:56:in `block in <top (required)>'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `call'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `block in exec_each_run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `each'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork.rb:69:in `exec_each_run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:12:in `block in run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:21:in `block in initialize'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:18:in `fork'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/forker.rb:18:in `initialize'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/mydocs/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/gems/spork-1.0.0rc3/lib/spork/server.rb:48:in `run'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1588:in `perform_without_block'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1548:in `perform'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1626:in `block (2 levels) in main_loop'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1622:in `loop'
/Users/mydocs/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/drb/drb.rb:1622:in `block in main_loop'
Additional restarts of the spork server have not changed anything. Any thoughts on what may be causing this/how to fix it? Thanks
EDIT: Added code from spec_helper.rb
Spork.each_run do
ActiveSupport::Dependencies.clear
ActiveRecord::Base.instantiate_observers <--- This is line 56
load "#{Rails.root}/config/routes.rb"
Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f }
end if Spork.using_spork?
This block was added so that I would no longer need to reset the spork server to get it to recognize changes to routes, however, I made this change earlier today and have successfully run many tests since then.
Observers were removed from Rails 4. Attempting to instantiate them will just not work. The code example you have is probably from Rails 3.
Remove that line. Nothing bad will happen.
Related
I'm trying to precompile + minify my js and css assets.
If I run: rake assets:precompile
Then it runs fine, but doesn't minify.
If I run: SECRET_KEY_BASE=rake secretRAILS_ENV=production rake assets:precompile
Then it returns an error message and doesn't compile: SassC::SyntaxError: Error: Invalid CSS after "}": expected 1 selector or at-rule, was '!function(){if("und' on line 17881 of stdin
I've tried updating various gems, changing some of the CSS, adding #import to application.scss, etc but none of it seems to be working.
Here's the full error message:
rake aborted!
SassC::SyntaxError: Error: Invalid CSS after "}": expected 1 selector or at-rule, was '!function(){if("und'
on line 17881 of stdin
>> }
-^
stdin:17881
/usr/local/rvm/gems/ruby-2.4.1/gems/sassc-2.0.0/lib/sassc/engine.rb:49:in `render'
/usr/local/rvm/gems/ruby-2.4.1/gems/sassc-rails-2.1.0/lib/sassc/rails/compressor.rb:29:in `call'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/sass_compressor.rb:28:in `call'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/usr/local/rvm/gems/ruby-2.4.1#global/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.4.1/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/usr/local/rvm/gems/ruby-2.4.1#global/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.4.1/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
What am I missing that will let it precompile and minify my js and css?
For anyone searching for this, in the end I just deleted two instances in my CSS and JS that included the problematic line (!function(){if().
Still not sure why they caused this error but as they were not actively used lines anyway (related to videos, which I don't currently use) I was happy enough to just delete and compile without them.
I met the same problem.
to solve it, the key is find what is the content of "stdin", so we have to modify your local gem file and add debug outputs:
# edit (/home/siwei/.asdf/installs/ruby/3.0.4/lib/ruby/gems/3.0.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb)
def call(*args)
input = if defined?(data)
data # sprockets 2.x
else
args[0][:data] #sprockets 3.x
end
# add these debug lines of code
puts "=== input is: "
File.write('/tmp/temp_scss', input)
puts "=== input end "
SassC::Engine.new(
input,
{
style: :compressed
}
).render
end
then run command:
RAILS_ENV=production bundle exec rails assets:precompile
then you will meet error, no worry, check out the file /tmp/temp_scss, find the "line 17881 of stdin", you will find the syntax error.
e.g. my error looks like:
just fix this bug and everything goes fine.
I am working on a Ruby on Rails application that uses MongoDB, and I have implemented basic Sunspot functionality. Here is some information about my environment
Rails 3.2.11
Mongo 2.4.3
Sunspot 2.0.0
gem mongo_mapper
gem sunspot_rails
gem sunspot_solr
gem sunspot_mongo_mapper
I previously had everything working, but now I am having problems. I can successfully run
bundle exec rake sunspot:solr:start
but then when I try
bundle exec rake db:seed
I get the following error:
rake aborted!
RSolr::Error::InvalidRubyResponse - 200 OK
Error: <result status="1">java.lang.NullPointerException
at org.apache.solr.handler.XmlUpdateRequestHandler.doLegacyUpdate(XmlUpdateRequestHandler.java:129)
at org.apache.solr.servlet.SolrUpdateServlet.doPost(SolrUpdateServlet.java:87)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1221)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:297)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
Request Data: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><add><doc><field name=\"id\">Event 5197f9061d41c853110005a1</field><field name=\"type\">Event</field><field name=\"class_name\">Event</field><field name=\"name_text\">TEST Event Name</field><field name=\"description_text\">TEST Event Description</field></doc></add>"
Backtrace: /var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:297:in `rescue in evaluate_ruby_response'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:294:in `evaluate_ruby_response'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:269:in `adapt_response'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:175:in `execute'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive'
(eval):2:in `post'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:67:in `update'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:87:in `add'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:106:in `add_documents'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:30:in `add'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session.rb:91:in `index'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:297:in `rescue in evaluate_ruby_response'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:294:in `evaluate_ruby_response'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:269:in `adapt_response'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:175:in `execute'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:161:in `send_and_receive'
(eval):2:in `post'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:67:in `update'
/var/lib/gems/1.9.1/gems/rsolr-1.0.9/lib/rsolr/client.rb:87:in `add'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:106:in `add_documents'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/indexer.rb:30:in `add'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot/session.rb:91:in `index'
/var/lib/gems/1.9.1/gems/sunspot- 2.0.0/lib/sunspot/session_proxy/abstract_session_proxy.rb:11:in `index'
/var/lib/gems/1.9.1/gems/sunspot-2.0.0/lib/sunspot.rb:184:in `index'
/var/lib/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:392:in `solr_index'
/var/lib/gems/1.9.1/gems/sunspot_rails-2.0.0/lib/sunspot/rails/searchable.rb:492:in `perform_index_tasks'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:431:in `_run__816338171__save__410491902__callbacks'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:405:in `__run_callback'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:385:in `_run_save_callbacks'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:81:in `run_callbacks'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/embedded_callbacks.rb:28:in `run_callbacks'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/callbacks.rb:17:in `create_or_update'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:129:in `save'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/dirty.rb:19:in `block in save'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/dirty.rb:37:in `clear_changes'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/dirty.rb:19:in `save'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/validations.rb:22:in `save'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/identity_map.rb:113:in `save'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:134:in `save!'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:31:in `block in create!'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:100:in `block in initialize_each'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:98:in `each'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:98:in `initialize_each'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/querying.rb:31:in `create!'
/my_home_dir/my_rails_app/db/seed_events.rb:4:in `<top (required)>'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/my_home_dir/my_rails_app/db/seeds.rb:16:in `block in <top (required)>'
/my_home_dir/my_rails_app/db/seeds.rb:16:in `each'
/my_home_dir/my_rails_app/db/seeds.rb:16:in `<top (required)>'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `block in load'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/var/lib/gems/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:245:in `load'
/var/lib/gems/1.9.1/gems/mongo_mapper-0.12.0/lib/mongo_mapper/railtie/database.rake:14:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:seed
(See full trace by running task with --trace)
I also get a similar error if I attempt bundle exec rake sunspot:reindex which has the same java.lang.NullPointerException stacktrace but a slightly different Ruby stacktrace.
UPDATE
Sorry that I haven't gotten around to this in so long. I finally tried deleting my solr/ directory and then restarting. I am now able to run bundle exec rake sunspot:solr:start and then bundle exec rake db:seed without any problems, but I still have an error when I try:
bundle exec rake sunspot:solr:reindex
I see the following stacktrace
$ bundle exec rake sunspot:solr:reindex
rake aborted!
undefined method `includes' for Event:Class
/home/my_username/.rvm/gems/ruby-1.9.3-p429/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/dynamic_querying.rb:39:in `method_missing'
/home/my_username/.rvm/gems/ruby-1.9.3-p429/gems/sunspot_rails-2.1.0/lib/sunspot/rails/searchable.rb:254:in `solr_index'
/home/my_username/.rvm/gems/ruby-1.9.3-p429/gems/sunspot_rails-2.1.0/lib/sunspot/rails/searchable.rb:203:in `solr_reindex'
/home/my_username/.rvm/gems/ruby-1.9.3-p429/bundler/gems/sunspot_mongo_mapper-b6cf3edca97a/lib/sunspot/mongo_mapper/tasks.rb:21:in `block (3 levels) in <top (required)>'
/home/my_username/.rvm/gems/ruby-1.9.3-p429/bundler/gems/sunspot_mongo_mapper-b6cf3edca97a/lib/sunspot/mongo_mapper/tasks.rb:20:in `each'
/home/my_username/.rvm/gems/ruby-1.9.3-p429/bundler/gems/sunspot_mongo_mapper-b6cf3edca97a/lib/sunspot/mongo_mapper/tasks.rb:20:in `block (2 levels) in <top (required)>'
/home/my_username/.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `eval'
/home/my_username.rvm/gems/ruby-1.9.3-p429/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => sunspot:solr:reindex => sunspot:reindex
(See full trace by running task with --trace)
So does anyone know what this problem is?
Any insight into this issue would be appreciated! Thanks!
I had the same error only it was triggered with bundle exec rake sunspot:solr:reindex, what helped was force quitting all java processes I could find. After I restarted SOLR with
bundle exec rake sunspot:solr:start
I could then reindex without any errors.
I encountered this error as well - https://stackoverflow.com/a/17665820/227403
The solution was that my solr directory came over in a SVN deploy. I deleted the directory and restarted it.
what's your solr/ directory structure, it should looks like:
sole/
conf/
data/
pids/
My local machine has this 3 folders, it works. But both of my 2 server have no conf/. one works, the other does not works.
Beginning I try to delete whole solr/ folder, and restart solr, the problem still exist, then I reinstall java, reinstall gems, the problem still exist.
At last I add conf/ with some configure files that automatic created by solr at my local machine, I push them to sever, solve the problem.
It cost my whole day, hope this answer helpful.
You should try using Pry & prey-debbugger to step in the last file and see what's going on.
/home/my_username/.rvm/gems/ruby-1.9.3-p429/gems/mongo_mapper-0.12.0/lib/mongo_mapper/plugins/dynamic_querying.rb:39:in `method_missing'
It's looking for something that no longer exists. Perhaps you've defined a field in Searchable that has been removed or changed?
After moving my Heroku app to Unicorn, New Relic stopped showing any reports except for deployments. I tried the solution suggested here: https://newrelic.com/docs/ruby/no-data-with-unicorn with no luck. I tried updating all gems, and now I get the error:
Exiting
/Users/bashar/.rvm/gems/ruby-1.9.3-preview1#global/gems/rpm_contrib-2.1.11/lib/rpm_contrib/instrumentation/mongoid.rb:13:in block (2 levels) in <top (required)>': uninitialized constant Mongoid::Collection (NameError)
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:53:incall'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:53:in block in execute'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:52:ineach'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:52:in execute'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:19:inblock in detect!'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:17:in each'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/vendor/gems/dependency_detection-0.0.1.build/lib/dependency_detection.rb:17:indetect!'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/lib/new_relic/control/instrumentation.rb:93:in _install_instrumentation'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/lib/new_relic/control/instrumentation.rb:52:ininstall_instrumentation'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/lib/new_relic/control/instance_methods.rb:76:in init_plugin'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/newrelic_rpm-3.6.0.83/lib/newrelic_rpm.rb:40:inblock in '
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in instance_exec'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/initializable.rb:30:inrun'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in block in run_initializers'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/initializable.rb:54:ineach'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in run_initializers'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/application.rb:136:ininitialize!'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in method_missing'
from /Users/bashar/rails-projects/myapp/config/environment.rb:5:in'
from /Users/bashar/rails-projects/myapp/config.ru:7:in block in <main>'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/builder.rb:51:ininstance_eval'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/builder.rb:51:in initialize'
from /Users/bashar/rails-projects/myapp/config.ru:1:innew'
from /Users/bashar/rails-projects/myapp/config.ru:1:in <main>'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/builder.rb:40:ineval'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/builder.rb:40:in parse_file'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/server.rb:200:inapp'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/commands/server.rb:46:in app'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/server.rb:301:inwrapped_app'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/rack-1.4.1/lib/rack/server.rb:252:in start'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/commands/server.rb:70:instart'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/commands.rb:55:in block in <top (required)>'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/commands.rb:50:intap'
from /Users/bashar/.rvm/gems/ruby-1.9.3-preview1/gems/railties-3.2.11/lib/rails/commands.rb:50:in <top (required)>'
from script/rails:6:inrequire'
from script/rails:6:in `'
I have the following gems in order:
gem 'rpm_contrib'
gem 'newrelic_rpm'
gem 'newrelic_moped'
I have had similar problem in the past when I upgraded to Mongoid 3, but back then the solution was newrelic_moped. Not this time it seems.
Any idea?
I had the same. Add the code below to config/initializers/newrelic.rb:
# Ensure the agent is started using Unicorn.
# This is needed when using Unicorn and preload_app is not set to true.
# See https://newrelic.com/docs/ruby/no-data-with-unicorn
if defined? Unicorn
::NewRelic::Agent.manual_start()
::NewRelic::Agent.after_fork(:force_reconnect => true)
end
I use delayed job to carry out background tasks in my app. It does some stuff and then sends a mail. This is an example of the code block preformed as a delayed job.
def task
# do stuff
AppMailer.post.some_template(#variable)
end
This has been working fine, I have a template in the correct directory some_template.text.plain.erb. I have started seeing this raise a MissingTemplate exception and this stops the delayed job and tries again after a given time (as expected when exceptions are raised in delayed job). Some cases this will fail 2 or 3 times and then deliver successfully, other cases there will be no exception raised. How can a template not exist then be found successfully upon the next attempt?
The error is looking for a template .erb is the plain.text.erb causing this problem. Any ideas why this is causing an intermittent problem? I have tried wrapping the sending of the mail in a rescue block as I would rather not send the mail than raise an exception.
def task
# do stuff
begin
AppMailer.post.some_template(#variable)
rescue ActionView::MissingTemplate => e
# do stuff
end
end
But the exception is still raised. Does delayed job do anything that might stop this rescue block working?
Here is the stack trace
Error:
Missing template app_mailer/some_template.erb in view path app/views:vendor/plugins/tolk/app/views
/data/app/shared/bundled_gems/ruby/1.8/gems/actionpack-2.3.14/lib/action_view/paths.rb:74:in `find_template'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionpack-2.3.14/lib/action_view/base.rb:264:in `render'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:600:in `render'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:586:in `render_message'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:526:in `create!'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:485:in `initialize'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:427:in `new'
/data/app/shared/bundled_gems/ruby/1.8/gems/actionmailer-2.3.14/lib/action_mailer/base.rb:427:in `method_missing'
/data/app/releases/20121127213524/app/models/mail_delivery.rb:55:in `send'
/data/app/releases/20121127213524/app/models/mail_delivery.rb:55:in `serialize_mail'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:178:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:178:in `evaluate_method'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:166:in `call'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:93:in `run'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:92:in `each'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:92:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:92:in `run'
/data/app/shared/bundled_gems/ruby/1.8/gems/activesupport-2.3.14/lib/active_support/callbacks.rb:276:in `run_callbacks'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:344:in `callback'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:265:in `create'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/base.rb:2927:in `create_or_update_without_callbacks'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/callbacks.rb:250:in `create_or_update'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/base.rb:2577:in `save_without_validation'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/validations.rb:1089:in `save_without_dirty'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/dirty.rb:79:in `save_without_transactions'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:229:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:229:in `with_transaction_returning_status'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/connection_adapters/abstract/database_statements.rb:136:in `transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:182:in `transaction_without_trace_ActiveRecord_self_name_transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/newrelic_rpm-3.4.0.1/lib/new_relic/agent/method_tracer.rb:491:in `transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/newrelic_rpm-3.4.0.1/lib/new_relic/agent/method_tracer.rb:242:in `trace_execution_scoped'
/data/app/shared/bundled_gems/ruby/1.8/gems/newrelic_rpm-3.4.0.1/lib/new_relic/agent/method_tracer.rb:486:in `transaction'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:228:in `with_transaction_returning_status'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:196:in `save'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:208:in `rollback_active_record_state!'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/transactions.rb:196:in `save'
/data/app/shared/bundled_gems/ruby/1.8/gems/activerecord-2.3.14/lib/active_record/base.rb:727:in `create'
/data/app/releases/20121127213524/app/models/mail_delivery.rb:88:in `method_missing'
/data/app/releases/20121127213524/lib/job_manifest.rb:670:in `notify_user_of_upload_without_audit'
/data/app/releases/20121127213524/lib/job_manifest.rb:6:in `send'
/data/app/releases/20121127213524/lib/job_manifest.rb:6:in `notify_user_of_upload_with_audit'
/data/app/releases/20121127213524/lib/job_manifests/app_send_job.rb:43:in `notify_user_of_upload'
/data/app/releases/20121127213524/lib/job_manifests/app_send_job.rb:43:in `extended'
/data/app/releases/20121127213524/lib/job_manifest.rb:102:in `preflight_completed_changed_delayed'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/performable_method.rb:35:in `send'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/performable_method.rb:35:in `perform'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/backend/base.rb:74:in `invoke_job'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:122:in `run'
/usr/lib64/ruby/1.8/timeout.rb:67:in `timeout'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:122:in `run'
/usr/lib64/ruby/1.8/benchmark.rb:308:in `realtime'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:121:in `run'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:173:in `reserve_and_run_one_job'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:106:in `work_off'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:105:in `times'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:105:in `work_off'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:80:in `start'
/usr/lib64/ruby/1.8/benchmark.rb:308:in `realtime'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:79:in `start'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:76:in `loop'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/worker.rb:76:in `start'
/data/app/shared/bundled_gems/ruby/1.8/gems/delayed_job-2.0.7/lib/delayed/command.rb:100:in `run'
(eval):1
/data/app/current/script/runner:3:in `eval'
/data/app/shared/bundled_gems/ruby/1.8/gems/rails-2.3.14/lib/commands/runner.rb:48
/data/app/current/script/runner:3:in `require'
/data/app/current/script/runner:3
I know there are a couple of problems here but any advice would be appreciated.
It's hard to say from just what you've posted but with Delayed Job Mailer errors I would typically check for two things:
That your workers are being restarted when you deploy new code, so that they are using the latest version of your app.
Are the arguments you're passing to the Mailer method used to retrieve records? If so be careful that records don't change or disappear between the job being created and the job being worked. Consider passing in exactly the attributes you need to build the mail if this is the case.
As part of my rails project, we are going to use a daemon as a message queue listener to execute commands coming from a Rails RESTful webservice front end.
For ease of prototyping, we are using the Daemons gem to create a very simple daemon. Right now, it's super simple. Here is the code:
require 'rubygems'
require 'daemons'
require File.expand_path('../../config/environment', __FILE__)
Daemons.run_proc('aeon_server') do
loop do
empires = Empire.all
sleep(5)
end
end
Basically, it requires the things for daemons, then requires my Ruby environment, then launches in to the daemon. The daemon simply attempts to query everything from the Empires table. Then it sleeps and does it again.
When it goes to execute 'all', I get the following exception:
C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb:109:in `write': closed stream (IOError)
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb:109:in `block in flush'
from <internal:prelude>:10:in `synchronize'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb:102:in `flush'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb:126:in `auto_flush'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb:67:in `add'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb:78:in `debug'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract_adapter.rb:206:in `rescue in log'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract_adapter.rb:199:in `log'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/sqlite_adapter.rb:135:in `execute'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/sqlite_adapter.rb:284:in `select'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/connection_adapters/abstract/query_cache.rb:56:in `select_all'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/base.rb:468:in `find_by_sql'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/relation.rb:64:in `to_a'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/activerecord-3.0.7/lib/active_record/relation/finder_methods.rb:143:in `all'
from C:in `all'
from script/aeon_server_control.rb:9:in `block (2 levels) in <main>'
from script/aeon_server_control.rb:7:in `loop'
from script/aeon_server_control.rb:7:in `block in <main>'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/application.rb:249:in `call'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/application.rb:249:in `block in start_proc'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/application.rb:260:in `call'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/application.rb:260:in `start_proc'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/application.rb:293:in `start'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/controller.rb:73:in `run'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons.rb:195:in `block in run_proc'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/cmdline.rb:109:in `call'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons/cmdline.rb:109:in `catch_exceptions'
from C:/Ruby/lib/ruby/gems/1.9.1/gems/daemons-1.1.3/lib/daemons.rb:194:in `run_proc'
from script/aeon_server_control.rb:6:in `<main>'
Any idea why ActiveSupport is throwing this exception? Are there additional steps I need to "bootstrap" my rails environment in to the daemon, beyond just requiring the environment?
There're some intricacies with regard to file descriptors when the process is forked/spawned/whatever-it-is-called-on-windows.
Try to reinstantiate a logger after you do Daemons.run_proc('aeon_server') with Rails.logger = ActiveSupport::BufferedLogger.new('/path/to/log')