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')
Related
Disclaimer: I know there are a couple of questions regarding this issue, but I followed all the answers. posted in those questions and I am still getting the error.
I have a rails app setup using Postgres and am trying to switch to mongoid. Here are the steps I took:
drop databases
add 'mongoid', '~> 7.0.5' and delete 'pg' gem
remove all references to active_record and active_storage
remove spring gems (known to cause issues)
update all models to be compatible with mongodb
delete config/database.yml and /db directory
switch devise and database-cleaner to use mongoid
After following all of the above steps, I am still getting the error when starting the server:
Could not load database configuration - No such file - [config/database.yml]
This doesn't make any sense, because rails should not be loading active record at all, and therefore should not be loading the database config file.
I would really appreciate if someone could be debug this issue.
You can view the source code of my app under the branch mongodb
Edit: I disabled bootsnap and devise and got the stack trace down to this: (It looks like active_record is still being loaded)
Puma caught this error: Cannot load database configuration:
Could not load database configuration. No such file - ["config/database.yml"] (RuntimeError)
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/railties-6.0.3.2/lib/rails/application/configuration.rb:241:in `database_configuration'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/railtie.rb:200:in `block (2 levels) in <class:Railtie>'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:71:in `class_eval'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:71:in `block in execute_hook'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:61:in `with_execution_control'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:66:in `execute_hook'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:51:in `each'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/base.rb:327:in `<module:ActiveRecord>'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/base.rb:27:in `<top (required)>'
/Users/afamily/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
/Users/afamily/.rvm/rubies/ruby-2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.3.0/lib/zeitwerk/kernel.rb:23:in `require'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activerecord-6.0.3.2/lib/active_record/query_cache.rb:31:in `run'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:28:in `before'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:428:in `block in make_lambda'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:200:in `block (2 levels) in halting'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:605:in `block (2 levels) in default_terminator'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:604:in `catch'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:604:in `block in default_terminator'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:201:in `block in halting'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:513:in `block in invoke_before'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:513:in `each'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:513:in `invoke_before'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/callbacks.rb:134:in `run_callbacks'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:111:in `run!'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:73:in `block in run!'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:70:in `tap'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/activesupport-6.0.3.2/lib/active_support/execution_wrapper.rb:70:in `run!'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/static.rb:126:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/actionpack-6.0.3.2/lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/webpacker-4.2.2/lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/railties-6.0.3.2/lib/rails/engine.rb:527:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/configuration.rb:228:in `call'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/server.rb:713:in `handle_request'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/server.rb:472:in `process_client'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/server.rb:328:in `block in run'
/Users/afamily/.rvm/gems/ruby-2.7.1/gems/puma-4.3.5/lib/puma/thread_pool.rb:134:in `block in spawn_thread'
I believe this is the same issue as https://github.com/rails/spring/issues/601, in your case originating from devise here:
/home/sandbox/agilely/vendor/bundle/ruby/2.7.0/gems/devise-4.7.2/lib/devise/models/confirmable.rb:52:in `block in <module:Confirmable>'
If you remove devise from your application and you are able to load console successfully, I suggest reporting this issue to devise.
Rails version: 6.0.2.1
Ruby version: 2.7.0p0
I added gem 'config' (https://github.com/rubyconfig/config) to my Rails 6 project, ran bundle install, and rails g config:install. Everything appeared to install correctly.
I can start the rails server successfully but when I actually open the app in the browser this lovely error (see below) is outputted in the Rails log and also outputted on to the page.
I have reproduced this on a fresh rails app following the same steps. However, this error only happened once a before_action was added to ApplicationController. Also, when I remove everything from my original projects ApplicationController, the error does not occur.
2020-05-02 15:34:53 -0700: Rack app error handling request { GET / }
#<NameError: uninitialized constant ActionText::Engine::ApplicationController>
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actiontext-6.0.2.1/lib/action_text/engine.rb:46:in `block (2 levels) in <class:Engine>'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:72:in `class_eval'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:72:in `block in execute_hook'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:62:in `with_execution_control'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:67:in `execute_hook'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:52:in `block in run_load_hooks'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:51:in `each'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/lazy_load_hooks.rb:51:in `run_load_hooks'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actiontext-6.0.2.1/lib/action_text/content.rb:132:in `<main>'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/zeitwerk-2.2.2/lib/zeitwerk/kernel.rb:23:in `require'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actiontext-6.0.2.1/lib/action_text/engine.rb:43:in `block (2 levels) in <class:Engine>'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:429:in `instance_exec'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:429:in `block in make_lambda'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:201:in `block (2 levels) in halting'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:607:in `block (2 levels) in default_terminator'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:606:in `catch'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:606:in `block in default_terminator'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:202:in `block in halting'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:514:in `block in invoke_before'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:514:in `each'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:514:in `invoke_before'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/callbacks.rb:134:in `run_callbacks'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:119:in `complete!'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:76:in `ensure in block in run!'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:76:in `block in run!'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:70:in `tap'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/activesupport-6.0.2.1/lib/active_support/execution_wrapper.rb:70:in `run!'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/static.rb:126:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rack-2.0.8/lib/rack/sendfile.rb:111:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/actionpack-6.0.2.1/lib/action_dispatch/middleware/host_authorization.rb:77:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/webpacker-4.2.2/lib/webpacker/dev_server_proxy.rb:23:in `perform_request'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/rack-proxy-0.6.5/lib/rack/proxy.rb:57:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/railties-6.0.2.1/lib/rails/engine.rb:526:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/puma-3.12.2/lib/puma/configuration.rb:227:in `call'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/puma-3.12.2/lib/puma/server.rb:674:in `handle_request'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/puma-3.12.2/lib/puma/server.rb:476:in `process_client'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/puma-3.12.2/lib/puma/server.rb:334:in `block in run'
/Users/sslade/.rbenv/versions/2.7.0/lib/ruby/gems/2.7.0/gems/puma-3.12.2/lib/puma/thread_pool.rb:135:in `block in spawn_thread'
Update:
Disabling actiontext resolves this issue. However, it is not not ideal especially if I decide I want to use it in the future.
config/application.rb
# require 'rails/all'
require 'rails'
require 'active_record/railtie'
require 'active_storage/engine'
require 'action_controller/railtie'
require 'action_view/railtie'
require 'action_mailer/railtie'
require 'active_job/railtie'
require 'action_cable/engine'
require 'action_mailbox/engine'
# require 'action_text/engine'
require 'rails/test_unit/railtie'
require 'sprockets/railtie'
After disabling ActionText, Rails let me know of some errors in ApplicationController. There was a line where I had =|| instead of||=. After fixing that syntax, my app loaded as expected.
I then added ActionText back in afterwards to see if it would load: it did! So it was in fact a simple syntax mistake in ApplicationController but for some reason I was getting an ActionText error instead the syntax error.
If there is any follow up as to why this issue may have occurred, please update this thread: https://github.com/rails/rails/issues/39130
Something strange is happening with my application when I boot the jobs server with rake jobs:work. The rails webserver boots fine. I've noticed threads such as this one, however 1) it's not quite the same error message, that one seems more straightforward and 2) the answer did not yield any different results.
Here's my stacktrace -
rake aborted!
Psych::BadAlias: Unknown alias: 1
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/psych_ext.rb:77:in `visit_Psych_Nodes_Mapping'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/psych_ext.rb:35:in `visit_Psych_Nodes_Mapping'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/psych_ext.rb:35:in `visit_Psych_Nodes_Mapping'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/psych_ext.rb:17:in `load_dj'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/backend/base.rb:85:in `payload_object'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/backend/base.rb:74:in `name'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:245:in `job_say'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:272:in `handle_failed_job'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:213:in `block in run'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:213:in `rescue in run'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:202:in `run'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:280:in `block in reserve_and_run_one_job'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:280:in `reserve_and_run_one_job'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:187:in `block in work_off'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:186:in `times'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:186:in `work_off'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:150:in `block (4 levels) in start'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:149:in `block (3 levels) in start'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:148:in `block (2 levels) in start'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:147:in `loop'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:147:in `block in start'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/plugins/clear_locks.rb:7:in `block (2 levels) in <class:ClearLocks>'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in `block (2 levels) in add'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:61:in `block in initialize'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:79:in `block in add'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:66:in `execute'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/lifecycle.rb:40:in `run_callbacks'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/worker.rb:146:in `start'
/Users/ccromar/.rvm/gems/ruby-2.4.0/gems/delayed_job-4.0.6/lib/delayed/tasks.rb:9:in `block (2 levels) in <top (required)>'
I got the same issue after ruby upgrade from 2.1.5 to 2.3.8. Thats latest ruby version that could be run with rails 4.1.8.
Upgrading to the latest version of delayed_job did not help. Also tried to specify downgraded version of psych gem in my Gemfile. This did work not as well.
The real issue is that if error appears on job parsing stage then delayed_job does not update last_error column.
So I just went though all the jobs and checked if it could be parsed or not:
failing_jobs = []
Delayed::Job.find_each do |job|
begin
# this code is from dj source https://github.com/collectiveidea/delayed_job/blob/master/lib/delayed/psych_ext.rb#L15
yaml = job.handler
result = Psych.parse(yaml)
result ? Delayed::PsychExt::ToRuby.create.accept(result) : result
rescue Psych::BadAlias => e
failing_jobs << job
end
end
In my case it were 6 jobs out of ~3k that could be deleted safely so I got lucky :)
Refs:
https://github.com/collectiveidea/delayed_job/pull/867
https://github.com/collectiveidea/delayed_job_mongoid/pull/65
In my Ruby on Rails application I have model that looks like this:
class Schema < ActiveRecord::Base
has_many :schema_items
def self.from_cache(schema_id)
schema = Rails.cache.read("schema_#{schema_id}")
unless schema
schema = Schema.where(id: schema_id).includes(:schema_items).first
Rails.cache.write("schema_#{schema_id}", schema) if schema
end
schema
end
end
I'm using this class method in other class which is called by Sidekiq worker. From time to time it returns the following error:
NotImplementedError
Using google I found this issue in redis_store gem: https://github.com/redis-store/redis-store/issues/74
But they fix this bug. My app is hosted on Heroku and I'm using the RedisCloud. Any ideas how can I solve this?
EDIT:
Here is the full backtrace:
NotImplementedError: NotImplementedError
from celluloid/tasks/task_fiber.rb:15:in `block in create'
from celluloid/tasks.rb:57:in `block in initialize'
from celluloid/actor.rb:357:in `block in task'
from celluloid/cell.rb:71:in `block in task'
from celluloid/cell.rb:60:in `block in invoke'
from celluloid/calls.rb:122:in `dispatch'
from celluloid/calls.rb:26:in `dispatch'
from celluloid/calls.rb:26:in `public_send'
from sidekiq/processor.rb:50:in `process'
from sidekiq/processor.rb:98:in `stats'
from sidekiq/processor.rb:51:in `block in process'
from sidekiq/middleware/chain.rb:132:in `invoke'
from sidekiq/middleware/chain.rb:132:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/middleware/server/logging.rb:11:in `call'
from sidekiq/logging.rb:30:in `with_context'
from sidekiq/middleware/server/logging.rb:15:in `block in call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/failures/middleware.rb:9:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/middleware/server/retry_jobs.rb:74:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/middleware/server/active_record.rb:6:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq/batch/middleware.rb:25:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidekiq_unique_jobs/middleware/server/unique_jobs.rb:16:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from sidetiq/middleware/history.rb:8:in `call'
from sidekiq/middleware/chain.rb:129:in `block in invoke'
from new_relic/agent/instrumentation/sidekiq.rb:29:in `call'
from new_relic/agent/instrumentation/controller_instrumentation.rb:352:in `perform_action_with_newrelic_trace'
from new_relic/agent/instrumentation/sidekiq.rb:33:in `block in call'
from sidekiq/middleware/chain.rb:127:in `block in invoke'
from sidekiq/processor.rb:52:in `block (2 levels) in process'
from sidekiq/processor.rb:75:in `execute_job'
from app/workers/response_processor_worker.rb:8:in `perform'
from app/services/import/response_processor.rb:28:in `process'
from app/models/import/importer/raw_response_validator.rb:17:in `validate'
from app/models/survey_schema.rb:51:in `from_cache'
from active_record/relation/finder_methods.rb:127:in `first'
from active_record/relation/finder_methods.rb:484:in `find_nth'
from active_record/relation/finder_methods.rb:500:in `find_nth_with_limit'
from active_record/relation.rb:243:in `to_a'
from active_record/relation.rb:514:in `load'
from active_record/relation.rb:643:in `exec_queries'
from active_record/relation.rb:643:in `each'
from active_record/relation.rb:644:in `block in exec_queries'
from active_record/associations/preloader.rb:102:in `preload'
from active_record/associations/preloader.rb:102:in `flat_map'
from active_record/associations/preloader.rb:102:in `each'
from active_record/associations/preloader.rb:103:in `block in preload'
from active_record/associations/preloader.rb:115:in `preloaders_on'
from active_record/associations/preloader.rb:143:in `preloaders_for_one'
from active_record/associations/preloader.rb:143:in `flat_map'
from active_record/associations/preloader.rb:143:in `each'
from active_record/associations/preloader.rb:144:in `block in preloaders_for_one'
from active_record/associations/preloader.rb:144:in `map'
from active_record/associations/preloader.rb:144:in `each'
from active_record/associations/preloader.rb:146:in `block (2 levels) in preloaders_for_one'
from active_record/associations/preloader/association.rb:20:in `run'
from active_record/associations/preloader/collection_association.rb:13:in `preload'
from active_record/associations/preloader/association.rb:78:in `associated_records_by_owner'
from active_record/associations/preloader/association.rb:60:in `owners_by_key'
from active_record/associations/preloader/association.rb:103:in `key_conversion_required?'
from active_record/associations/preloader/association.rb:107:in `association_key_type'
from active_record/associations/preloader/association.rb:45:in `association_key_name'
and my worker looks like this:
class ResponseCreatorWorker
include Sidekiq::Worker
sidekiq_options queue: :response_processing
def perform(schema_id)
# some not important code
schema = Schema.from_cache(schema_id) # this line throws the error
Response.create(schema: schema)
end
end
A couple options without being able to go into the Pro code:
Error you found is redis-store related, try memcached
Try moving the cache to memcached, it should be a simple and non-disruptive action, cost-free on simple plans, and see if the problem goes away, or changes, could be useful for hunting the core bug down
memcache is a better caching service anyway for simple key-value stuff,
The worker you linked is not a part of the stack trace
You showed the ResponseCreatorWorker, but that does not appear in the stack trace. What appears is ResponseProcessorWorker, maybe link that worker instead?
Are you sure you are running the code you are running?
Mike Perham says that the Sidekiq backtrace doesn't match the version you have given him, and the wrong worker is in the stack trace? Are you really sure the server is updating? Review the deployment log and log in to the worker with heroku run bash and inspect a couple of key files, make sure nothing is off with the platform.
Can you rescue it? :D
It should be pretty safe to put in a rescue that catches NotImplementedError, tries once again, and logs a record of it into the logs. Update gems when appropriate and when warnings disappear open a whiskey and celebrate.
Put something like this in your model:
def wrap_me_scotty
yield
rescue NotImplementedError => e
warn "#{e} :-("
yield # try once more, let it explode if no joy
end
and then wrap Rails.cache calls
def self.from_cache(schema_id)
schema = wrap_me_scotty{ Rails.cache.read("schema_#{schema_id}") }
unless schema
schema = Schema.where(id: schema_id).includes(:schema_items).first
wrap_me_scotty{ Rails.cache.write("schema_#{schema_id}", schema) } if schema
end
schema
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.