0

我正在使用 devise 和 devise-async,它使用 devise-async 使用 sidekiq 发送电子邮件。但最近它停止工作,我无法找到问题。

我正在使用的宝石

    gem 'devise'
    gem 'devise-async'

配置/初始化程序/设计-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

用户.rb

  devise :database_authenticatable,:async,
         :recoverable, :rememberable, :validatable,
         :lockable, :timeoutable, :trackable

我用命令运行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" = $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)
4

1 回答 1

0

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

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

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

config.action_mailer.deliver_later_queue_name = 'default'
于 2021-09-29T07:02:55.257 回答