devise-async 不使用 sidekiq 执行排队作业

devise-async not executing enqueue jobs with sidekiq

我正在使用 devise 和 devise-async,它使用 devise-async 通过 sidekiq 发送电子邮件。 但是最近它停止工作了,我找不到问题所在。

我正在使用的宝石

    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 运行 sidekiq 与命令

 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 在邮件队列中排队作业但不转发它。

我的终端响应

D, [2021-09-16T19:20:07.754589 #51261] DEBUG -- :   User Load (0.8ms)  SELECT "users".* FROM "users" WHERE "users"."email" =  ORDER BY "users"."id" ASC LIMIT   [["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" =  ORDER BY "users"."id" ASC LIMIT   [["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" = , "reset_password_sent_at" = , "updated_at" =  WHERE "users"."id" =   [["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 (, , , , , ) 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: \"api21jeHYC46FPJ/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)

发生这种情况是因为 ActionMailer 使用 mailers 队列作为默认队列来发送电子邮件。

运动鞋也默认使用邮件队列发送邮件。但是队列中没有名为 mailers 的 Worker。

通过在我的 application.rb 中添加以下行解决了我的问题。

config.action_mailer.deliver_later_queue_name = 'default'