Dalli Server Not Found When Running Delayed_Job - ruby-on-rails

When running a job with delayed_job, I get errors when trying to access the Dalli Cache.
The Dalli cache is initialized in environment.rb with the following...
CACHE = Dalli::Client.new(['localhost:11211'], {:namespace=>my_namespace_method})
When the code executes CACHE.get 'my_key' in my rails app, everything runs fine.
When it runs in a delayed_job worker, it errors with No Server Available
Other info that might help:
I have confirmed that the memcached server is running and is accessible via telnet on localhost:11211
We're running Ruby 1.9.2 under rvm

Related

Unable to restart production rails server when started as daemon

I am running a rails server on an Ubuntu EC2 instance and have run into an issue when it comes to deploying (and restarting) my server. The odd thing is; everything seems to work fine when I start a vanilla server (rails server), but when I start the server as a daemon it does not reset (rails server -d).
I use Capistrano to do deployment. As far as I can tell there is no issue; it pulls down my latest branch, runs migrations and does a touch tmp/restart.txt. I had tried making my tmp/restart.txt a shared file, but that does not seem to be the issue (although it is a configuration I think I'll keep). After discovering Capistrano is likely working as expected I tried sshing into the server and running touch tmp/restart.txt myself. It works for the vanilla server but not the daemon.
Has anyone seen this issue before? If there is more info I could provide please let me know!
Env:
ruby 2.6.3p62 #/home/deploy/.rvm/rubies/ruby-2.6.3/bin/ruby
Rails 5.2.3 #/home/deploy/.rvm/gems/ruby-2.6.3/bin/rails
Bundler version 2.1.2 #/home/deploy/.rvm/gems/ruby-2.6.3/bin/bundle
Node v13.8.0 #/home/deploy/.nvm/versions/node/v13.8.0/bin/node
My logs, tmp, and config/master.key are shared as part of my Capistrano setup.
are you using puma or unicorn or passenger? apache or nginx? restarting the process depends more on that than anything.
personally, I like using Passenger with apache and when I restart apache, the passenger process restarts automatically.

Rails 5: Using Capybara with Phusion Passenger

I am trying to run specs on a Rails 5 app. However, I am seeing the following LoadError:
Failure/Error: raise LoadError, 'Capybara is unable to load puma for
its server, please add puma to your project or specify a different
server via something like Capybara.server = :webrick.'
I am using the passenger gem for the production server. Is there a way in which I can use passenger for the Capybara tests as well?
Thanks in advance
If you really want to use passenger to run your app while testing you will need to startup your app separately with passenger using the rails test environment (so it uses the test DB, etc) and then set
Capybara.run_server = false
Capybara.app_host = "http://<wherever the app is accessible>"
for your tests. This tells Capybara not to bother with running the app itself and to just connect to the app you're already running. You will also need to use something like database_cleaner to handle database resetting between tests, and be very careful to make sure you don't have any leftover requests running at the end of each test.
When running the tests with puma or webrick none of that is required (database_cleaner is generally required for rails < 5.1 but not 5.1+), because the web server is run in the same process (different threads) as the tests which allows Capybara to know when requests are still being processed and for Rails to share the DB connection with the tests. Overall you're just going to have a much smoother experience if you stick with puma or webrick for your tests.
I don't think you can do this:
The capybara documentation:
This block takes a rack app and a port and returns a
rack server listening on that port
From the passenger repo:
This is fundamentally incompatible with Phusion Passenger's model.
Such a Rack handler implies a single application and a single process.
Phusion Passenger runs multiple processes which can even serve multiple
applications.

Running byebug with Heroku Local

I'm trying to run byebug so that it works with Heroku Local.
By default, the breakpoints don't give me access to an irb console like they might if I was using rails s. I tried byebug's remote debugging as described here but something about running the byebug server slows my local server down to a crawl and it's unusable. Is there anyway to get byebug to work with Heroku Local? Is there any alternative debugging solution that works well for Rails and Heroku Local?

Prevent foreman to crash when typo in code

I am using foreman gem on my Rails project to handle the different processes to be launched at startup (web, mailer, delayed job, ...).
It's working as expected but if I save a file with a typo or try to access a property on a nil object, foreman crash for all processes. I have to manually kill each ruby and node (for maildev) processes in order to run foreman start again.
Is there a way to prevent foreman to crash as the plumber plugin for gulp tasks ?
Thanks !
My project:
Rails 4.2
Ruby 2.2.0
Foreman
Server Unicorn
Mac OSX

Delayed_job "Undefined method" in production. (Passenger, no RVM)

I've seen this error pop up in other places, but my circumstances seem to be somewhat unique. I'm running delayed_job (2.1.4) on my production server, which is using nginx, passenger, ruby 1.9.2, and rails 3.0.10. It is not using RVM. My jobs were running fine until my last code deploy, and now they all fail, with this message in the log:
--- !ruby/struct:Delayed::PerformableMailer
object: !ruby/object:Class TemplateMailer
method_name: :send_email
#snip
{undefined method `send_email' for #<Class:0x00000007523e90>
I looked through similar answers here, and on delayed_job's wiki, but haven't been able to crack it.
Everything is running fine on a VM staging server that I set up, so what could the problem be in production?
make sure you don't have a setup_load_paths.rb in your config directory

Resources