Sidekiq作业不断出现在Rails应用中

问题描述 投票:0回答:1

我有一个Sidekiq作业,它可以从死里复活-即使在Sidekiq Web UI中删除了该作业之后,它仍然设法重新运行。现在已经进行了两个多月,删除作业后,当我启动Rails应用程序时它将发送。

Sidekiq UI

该工作是邀请系统的一部分,其中邀请者在有人接受邀请时收到电子邮件通知。我从来没有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" = $1 AND "members"."id" = $2 LIMIT $3  [["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\" = $1]","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\\\" = $1]\",\"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" = $1]

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
ruby-on-rails sidekiq
1个回答
0
投票

如果确实是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

© www.soinside.com 2019 - 2024. All rights reserved.