I was working with devise and devise-async and it was sending emails with sidekiq using devise-async. But recently it stops to work and I am not able to find the issue.
Gems I'm using
gem 'devise'
gem 'devise-async'
config/initilizer/devise-async.rb
Devise::Async.setup do |config|
config.enabled = true
end
passwords_controller.rb
def create
#Here im sending emails with the below command
self.resource =resource_class.send_reset_password_instructions(resource_params)
yield resource if block_given?
end
user.rb
devise :database_authenticatable,:async,
:recoverable, :rememberable, :validatable,
:lockable, :timeoutable, :trackable
im running sidekiq with the command
sidekiq -q default -q mailer
Sidekiq.rb
config = YAML.load(ERB.new(IO.read(Rails.root + 'config' + 'redis.yml')).result)[Rails.env].with_indifferent_access
redis_conn = {url: "redis://localhost:6379/0"}
Sidekiq.configure_server do |s|
s.redis = redis_conn
end
Sidekiq.configure_client do |s|
s.redis = redis_conn
end
Sidekiq Enqueued jobs in mailer queue but not sending it forward.
My Terminal Response
D, [2021-09-16T19:20:07.754589 #51261] DEBUG -- : User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."email" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["email", "moontesting@gmail.com"], ["LIMIT", 1]]
D, [2021-09-16T19:20:07.755562 #51261] DEBUG -- : ↳ app/controllers/api/v1/passwords_controller.rb:10:in `create'
D, [2021-09-16T19:20:07.821428 #51261] DEBUG -- : User Load (0.5ms) SELECT "users".* FROM "users" WHERE "users"."reset_password_token" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["reset_password_token", "113ee2379de9d55cccce204afba81fea68dcfd6e0a168a031e144d518f"], ["LIMIT", 1]]
D, [2021-09-16T19:20:07.821880 #51261] DEBUG -- : ↳ app/controllers/api/v1/passwords_controller.rb:10:in `create'
D, [2021-09-16T19:20:07.823659 #51261] DEBUG -- : (0.4ms) BEGIN
D, [2021-09-16T19:20:07.824224 #51261] DEBUG -- : ↳ app/controllers/api/v1/passwords_controller.rb:10:in `create'
D, [2021-09-16T19:20:07.825034 #51261] DEBUG -- : User Update (0.6ms) UPDATE "users" SET "reset_password_token" = $1, "reset_password_sent_at" = $2, "updated_at" = $3 WHERE "users"."id" = $4 [["reset_password_token", "113ee2379de9d55cccce20422afba81fea68dcfda18a031e144d518f"], ["reset_password_sent_at", "2021-09-16 14:20:07.822110"], ["updated_at", "2021-09-16 14:20:07.822562"], ["id", 2]]
D, [2021-09-16T19:20:07.825480 #51261] DEBUG -- : ↳ app/controllers/api/v1/passwords_controller.rb:10:in `create'
D, [2021-09-16T19:20:07.834650 #51261] DEBUG -- : PaperTrail::Version Create (0.6ms) INSERT INTO "versions" ("item_type", "item_id", "event", "whodunnit", "object", "created_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["item_type", "User"], ["item_id", "2"], ["event", "update"], ["whodunnit", "Unknown user"], ["object", "---\nreset_password_token: 78e745c5b2f23d539cbfcbd024209173539865e40da2885cfadfa72fbc4f1e6c\nreset_password_sent_at: 2021-09-16 14:15:51.921573000 Z\nid: 2\nfirst_name: moon\nlast_name: abc\nemail: moontesting10@gmail.com\nencrypted_password: \"$2a$11$8pi21jeHYC46FPJ/UEjLlOtNzoIkkZ/QooN68VpjWWuIUUqtICeWm\"\nremember_created_at: \nsign_in_count: 0\ncurrent_sign_in_at: \nlast_sign_in_at: \ncurrent_sign_in_ip: \nlast_sign_in_ip: \nconfirmation_token: \nconfirmed_at: \nconfirmation_sent_at: \nunconfirmed_email: \nfailed_attempts: 0\nunlock_token: \nlocked_at: \ncreated_at: 2021-09-16 12:06:20.985299000 Z\nupdated_at: 2021-09-16 14:15:51.921944000 Z\norganization_id: \npassword_changed_at: \ndeleted_at: \n"], ["created_at", "2021-09-16 14:20:07.822562"]]
D, [2021-09-16T19:20:07.835285 #51261] DEBUG -- : ↳ app/controllers/api/v1/passwords_controller.rb:10:in `create'
D, [2021-09-16T19:20:07.838491 #51261] DEBUG -- : (1.1ms) COMMIT
D, [2021-09-16T19:20:07.838981 #51261] DEBUG -- : ↳ app/controllers/api/v1/passwords_controller.rb:10:in `create'
I, [2021-09-16T19:20:07.853680 #51261] INFO -- : [ActiveJob] Enqueued ActionMailer::MailDeliveryJob (Job ID: d49ca82c-6418-4848-8268-3ec72407f828) to Sidekiq(mailers) with arguments: "Devise::Mailer", "reset_password_instructions", "deliver_now", {:args=>[#<GlobalID:0x000055ee3c2adac0 @uri=#<URI::GID gid://portal/User/2>>, "bGhQf9WdhEN_sj2pA1TT", {}]}
I, [2021-09-16T19:20:07.859059 #51261] INFO -- : Rendering api/v1/passwords/create.json.jbuilder
I, [2021-09-16T19:20:07.859715 #51261] INFO -- : Rendered api/v1/passwords/create.json.jbuilder (Duration: 0.6ms | Allocations: 226)
I, [2021-09-16T19:20:07.860110 #51261] INFO -- : Completed 200 OK in 1846ms (Views: 5.0ms | ActiveRecord: 10.8ms | Allocations: 118648)
This happens because ActionMailer uses the mailers
queue as default queue to send emails.
Sneakers also using mailers queue to send emails by default. But there is no Worker for queue named mailers.
By adding the following line in my application.rb
solved my issue.
config.action_mailer.deliver_later_queue_name = 'default'