Rails 4.2 - Sidekiq Not Sending Emails in Development

Rails 4.2 - Sidekiq not sending emails in development

You need to bootup sidekiq with the mailer queue for it to pick up these jobs:

bundle exec sidekiq -q default -q mailers

The Sidekiq Wiki goes over the scenarios in detail here.

Ruby on Rails - Sidekiq not sending email, stay lock up in schedule tasks

The problem is with your namespace. Don't use namespaces, as I wrote in my blog last year.

The redis-namespace gem allows you to share a Redis database among several applications by prefixing every key with a namespace but it's a terrible hack that no one should use. Redis already has a native solution if you want to share a Redis instance: databases. The default database is 0. Here's how to point Sidekiq to use database 1 instead:

https://www.mikeperham.com/2017/04/10/migrating-from-redis-namespace/

Why Sidekiq 4 does not work with mailer correctly?

In Gemfile line gem 'rspec-sidekiq' should be in group :test.

This gem changes sidekiq configurations and works bad with Sidekiq 4.X.X versions.

group :test do
gem 'rspec-sidekiq'
end

But I still don't know why redis URL is nil in logs...

Also, sidekiq 4.0.2 does not need sidekiq_mailer gem for async mail delivering.

Sidekiq/Redis/Rails - Sending was working on the branch, but now will not deliver on development

The answer turned out to be that production needs a LOT of settings to get sidekiq to work.

The first main change was adding a sidekiq.rb initializer:

Sidekiq.default_worker_options = {
backtrace: true,
retry: true
}

sidekiq_redis = lambda do
Redis.new(url: ENV['REDIS_URL'], ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE })
end

Sidekiq.configure_client do |config|
config.redis = ConnectionPool.new(size: 2, &sidekiq_redis)
end

Sidekiq.configure_server do |config|
config.redis = ConnectionPool.new(size: 17, &sidekiq_redis)
end

Sidekiq::Extensions.enable_delay!

Note that some of that (the OpenSSL part) is from a NEW issue we had to solve, when we upgraded from the free heroku redis plan to the lowest paid tier. TIP: Your app will crash if you upgrade to the first paid tier without making a bunch of adjustments. So do a lot of research before you do leave the free heroku redis plan.

We also had to add a new WORKER. We originally just had one regular dyno. We had to actually add a worker, like this:

Image from Heroku Showing the Worker We Added

Notice that there's still a sidekiq.yml. You need that too:

:verbose: true
:concurrency: 15
:queues:
- [mailers, 7]
- [default, 5]
- List item

Further, if you use actioncable, you'll likely have to update the actioncable.yml file as well:

development:
adapter: redis
url: redis://localhost:6379/1

test:
adapter: async

production:
adapter: redis
url: <%= ENV['REDIS_URL'] %>
ssl_params:
verify_mode: <%= OpenSSL::SSL::VERIFY_NONE %>

Again, that last part, with the ssl_params is to fix the issues caused when upgrading to the paid tier of redis.

NOTE: Although our emails deliver now, we haven't yet fully solved the SSL issue. We have a support ticket in with Heroku. But I'm hoping at least this will help you to better see what you may need to change to get sidekiq to work initially.

One final note: we learned that RedisToGo only works with Redis 4 or something. So if you want to use sidekiq, you can't use RedisToGo, because it doesn't apparently work with Redis 4. You need to use Heroku Redis. That was another change we made, which allowed sidekiq to work on production.

ActiveJob deliver_later not sending

Mailers are queued in the queue mailers. Remember to start sidekiq processing that queue:

bundle exec sidekiq -q default -q mailers

Or add config/sidekiq.yml with the following content

  :verbose: true
:concurrency: 25
:queues:
- [mailers, 7]
- [default, 5]

And run bundle exec sidekiq -C config/sidekiq.yml

Rails 4 - Mailer deliver_later not doing what I expect, blocks the UI

deliver_later uses ActiveJob to provide asynchronous execution.

However ActiveJob does not provide asynchronicity itself - it is a unifying api layer that can be fulfilled by many backends. The default one just runs everything inline it is not async.

To get async usage you need to pick an asynchronous backend. You can configure the backend in your application's config

 config.active_job.queue_adapter = ...

In general most adapters require a corresponding gem (eg delayed_job, sidekiq, sucker_punch) which may have their own dependencies too (for example sidekiq requires that you use redis.



Related Topics



Leave a reply



Submit