Sidekiq Job 不断出现在 Rails 应用程序中

Sidekiq Job Keeps Reappearing in Rails App

我有一个 Sidekiq 作业一直在死里复活 - 即使在删除 Sidekiq Web 中的作业后 UI 它仍然设法 re-run。这已经持续两个多月了,删除作业后,当我启动 Rails 应用程序时,它会发送。

该工作是邀请系统的一部分,当有人接受邀请时,邀请者会收到一封电子邮件通知。我从来没有 37 条会员记录,所以不清楚它是如何寻找 ID 37 的,也不清楚工作如何继续 运行。有什么想法吗?

控制台日志

16:03:42 web.1           | [19555] - Worker 0 (pid: 20745) booted, phase: 0
16:03:42 sidekiq.1       |   FacilityMember Load (1.4ms)  SELECT "members".* FROM "members" WHERE "members"."type" =  AND "members"."id" =  LIMIT   [["type", "FacilityMember"], ["id", 37], ["LIMIT", 1]]
16:03:42 sidekiq.1       | 2019-12-26T21:03:42.760Z pid=19576 tid=ovbl501oc class=ActionMailer::MailDeliveryJob jid=d991b5a607693bfc5e78305f elapsed=1.735 INFO: fail
16:03:42 sidekiq.1       | 2019-12-26T21:03:42.760Z pid=19576 tid=ovbl501oc WARN: {"context":"Job raised exception","job":{"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped":"ActionMailer::MailDeliveryJob","queue":"mailers","args":[{"job_class":"ActionMailer::MailDeliveryJob","job_id":"84b9126d-0319-44c6-a6cc-df790d577e7d","provider_job_id":null,"queue_name":"mailers","priority":null,"arguments":["InviteMailer","facility_invite_accepted","deliver_now",{"args":[{"_aj_globalid":"gid://openunit/FacilityMember/37"}],"_aj_symbol_keys":["args"]}],"executions":0,"exception_executions":{},"locale":"en","timezone":"UTC","enqueued_at":"2019-10-13T00:49:50Z"}],"retry":true,"jid":"d991b5a607693bfc5e78305f","created_at":1570927790.259349,"enqueued_at":1577394221.019845,"error_message":"Error while trying to deserialize arguments: Couldn't find FacilityMember with 'id'=37 [WHERE \"members\".\"type\" = ]","error_class":"ActiveJob::DeserializationError","failed_at":1570927790.303255,"retry_count":8,"retried_at":1577389107.42818},"jobstr":"{\"class\":\"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper\",\"wrapped\":\"ActionMailer::MailDeliveryJob\",\"queue\":\"mailers\",\"args\":[{\"job_class\":\"ActionMailer::MailDeliveryJob\",\"job_id\":\"84b9126d-0319-44c6-a6cc-df790d577e7d\",\"provider_job_id\":null,\"queue_name\":\"mailers\",\"priority\":null,\"arguments\":[\"InviteMailer\",\"facility_invite_accepted\",\"deliver_now\",{\"args\":[{\"_aj_globalid\":\"gid://openunit/FacilityMember/37\"}],\"_aj_symbol_keys\":[\"args\"]}],\"executions\":0,\"exception_executions\":{},\"locale\":\"en\",\"timezone\":\"UTC\",\"enqueued_at\":\"2019-10-13T00:49:50Z\"}],\"retry\":true,\"jid\":\"d991b5a607693bfc5e78305f\",\"created_at\":1570927790.259349,\"enqueued_at\":1577394221.019845,\"error_message\":\"Error while trying to deserialize arguments: Couldn't find FacilityMember with 'id'=37 [WHERE \\"members\\".\\"type\\" = ]\",\"error_class\":\"ActiveJob::DeserializationError\",\"failed_at\":1570927790.303255,\"retry_count\":8,\"retried_at\":1577389107.42818}"}
16:03:42 sidekiq.1       | 2019-12-26T21:03:42.760Z pid=19576 tid=ovbl501oc WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: Couldn't find FacilityMember with 'id'=37 [WHERE "members"."type" = ]

Sidekiq.rb

# frozen_string_literal: true

require 'sidekiq/testing/inline'

RSpec.configure do |config|
  config.after(:each, :sidekiq) do
    Sidekiq::Worker.clear_all
  end

  config.after(:each, :sidekiq, :redis) do
    Sidekiq.redis do |connection|
      connection.redis.flushdb
    end
  end
end

如果确实如此 config/initializers/sidekiq.rb 那么您的 Sidekiq 已配置好进行测试。

特别是 require 'sidekiq/testing/inline' 将它放在 inline test mode 中,这会导致 Sidekiq 立即执行作业。其余配置用于 RSpec 测试框架。

这应该放在一个独立的测试目录中,例如 spec/support/config/。在 spec/rails_helper.rb.

中加载类似这样的内容
Rails.root.join('spec/support/').glob('**/*.rb') { |f| require f }

Clean RSpec configuration directory structure for Ruby on Rails gems needed in testing