ActionView::MissingTemplate on initial attempt to deliver email with Sidekiq - ruby-on-rails

I keep getting errors reported to Honeybadger that various mailer fail from being unable to find the template like: ActionView::MissingTemplate: Missing template user_mailer/send_invitation with "mailer". Searched in: * "user_mailer". I have found a way I can reliably reproduce it is by restarting the Unicorn workers or ssh'ing into the server and using the Rails console to manually trigger the email. To make things more interesting, it only throws this error if I use deliver_later but not if I use deliver_now. Obviously I want to deliver emails asynchronously, so using deliver_now isn't really an option unless I make my own job that trigger the email manually, but that doesn't seem optimal.
Sidekiq.yml
production:
:concurrency: 10
:queues:
- default
- mailers
- elasticsearch
- searchkick
It still delivers the emails on the second attempt, so I'm not sure if this has to do with some loading of Sidekiq or something. Any help is greatly appreciated.
Using Rails 5.0.0, Sidekiq 4.1.4, and ActiveJob 5.0.0.

it tells that there's no required file, simply create the file:
app/views/user_mailer/send_invitation.html.erb

It turns out that when I upgraded Sidekiq from 4.0.4 to 4.1.4 it didn't kill my old process so it was hanging around undetected by monit and still plucking jobs from redis. Killed the old processes and it is all fine now. Thanks for every ones feedback.

Related

Sidekiq job keeps running in Rails, even though it isn't in the codebase

I used to have a job called DeleteYearOldApplicationsJob, we removed the job but it still runs in Sidekiq even though I have cleared the queues. There isn't reference to this job in the code any longer.
I know it runs because I get reports in my application monitor that says NameError: uninitialized constant DeleteYearOldApplicationsJob in sidekiq#DeleteYearOldApplicationsJob.
I ran this in the console to clear the jobs
Sidekiq::RetrySet.new.clear
Sidekiq::ScheduledSet.new.clear
Sidekiq::Stats.new.reset
Sidekiq::DeadSet.new.clear
This is an older project, Rails 4.2.8 and Sidekiq 5.0.5.
Thanks for your help in advance.

Sidekiq, Redis, Rails and Ruby - no implicit conversion of Pathname into String

I am trying to get my sidekiq server and client up and running (using Foreman), but whenever it gets to:
bundle exec sidekiq
The following results:
no implicit conversion of Pathname into String
Just like that, without Type Error preceding it - obviously the stack trace followed (will post if it will help). It says that the problem is in active_support/dependencies.rb (version 5.0.0.1) in the require method. Earlier in the stack trace it gets to boot_system in sidekiq's cli.rb (version 4.1.2). I am not sure whether this is a known issue with sidekiq or whether I am missing some configuration (I have read through a good number of tutorials on this which include thorough discussion of considerations to make in regarding sidekiq, puma and redis' configs, but to no avail). I am running Ruby 2.3.1 and Rails 5.0.0.1
The sidekiq.yml file includes (I got the error before this file and including it did not solve the issue):
development:
:concurrency: 5
production:
:concurrency: 20
:queues:
- default
Also, I am really new to posting on stackoverflow (but have made frequent use of it in the past). Any guidance would be great!
So I did manage to get my sidekiq up and running with redis. My problem was with one of the worker scripts which had an error in it... It was picking it up in a directory other than app/workers (I placed it in app/temp while I was debugging) - only saw it now in the stack trace: obviously missed it earlier due to looking at a screen too long (the classics). Still was weird that the error message was missing Type Error though.

what causes 'deadlock; recursive locking' error in a Rails app?

My rails app tracks any delayed_job errors, and we saw this one today for the first time:
deadlock; recursive locking /app/vendor/bundle/ruby/1.9.1/gems/delayed_job-3.0.5/lib/delayed/worker.r
The app has been performing flawlessly, with millions of delayed jobs handled w/o error.
Is this just "one of those random things" or is there something different we can/should do to prevent it from happening again?
I'm especially confused because we run only a single worker.
Our setup: Rails 3.2.12, Heroku app, Postgres, several web dynos but only 1 worker dyno.
This is an issue with Rack. See similar bug reports:
https://github.com/rack/rack/issues/658
https://github.com/rack/rack/issues/349
I had the same issue. The fix was to upgrade rubygems. The way I used to upgrade:
gem update --system
Ref: https://github.com/pry/pry/issues/2137#issuecomment-720775183

delayed_job dies with out error -- leaving job in locked state

After DJ dies the log files indicate nothing.
running: ./script/delayed_job status
gives: pid-file for killed process 1143 found (/appPath/tmp/pids/delayed_job.pid), deleting.
delayed_job: no instances running
The strange thing is if I use: ./script/delayed_job run It will run perfectly in the foreground! And never dies.
Tried many versions of delayed_job and mongoid with same results.
Any one know how to debug?
Using:
rails (3.2.7)
delayed_job_mongoid (2.0.0)
mongoid (3.0.3)
delayed_job (3.0.3)
Turns out delayed_job was executing a job causing a segmentation fault, which would kill the delayed_job daemon.
After debugging it turns out Random.rand() will cause a reproducible segmentation fault when run in a daemonized environment. This has to do with initial seeding and setup of the random generator, which apparently does not get handled properly by daemonize.
The solution: Random.new.rand()
I'm wondering if the weird behaviour in this stack overflow DJ log question could account for the behaviour you had. The answer looks plausible too. Stranger things have happened.
Pt 2:
Permission issues? could may very well be mucking it up too. Is this in production or dev? Does it work in Dev?
PT 3: From the github page of DJm Make sure you are using MongoDB version 1.3 or newer. Are you?
pt 4: and this? script/rails runner 'Delayed::Backend::Mongoid::Job.create_indexes'
Lastly, as of today DJM is running red on Travis, with some errors that may effect you. I had a shoddy build in a gem once, driving me to drink only to be fixed 2 days later. http://travis-ci.org/#!/collectiveidea/delayed_job_mongoid/jobs/1962498
If that isn't it, throw on pry in the Gemfile, add binding.pry to that script starting at the top and working down.

Delayed_job is not working correctly

I implemented the delayed job & it is processing fine but it is generating the mails in development.log not in production.log.
Also no mail is actually sent, it's just generating in development log. After processing I have no job in delayed job table also.
I also used RAILS_ENV=production rake jobs:work but still the mail is in development log and is not actually sent; I am using mail server on Ubuntu to send mails.
I have noticed that rake jobs:work by default uses the development log don't know is it same for the production server too?
If somebody know the problem then please answer ASAP because my application has been stuck due to this on the production server and lots of mails are just going in development log and not actually going to the end user.
This may be obvious, but in your config/production.rb, have you set
config.action_mailer.delivery_method = :smtp
It's possible you set the delivery method in config/development.rb, but forgot to do the same in the production environment. Please let me know so I can help further!

Resources