Reputation: 324
I have a Sidekiq job that keeps resurrecting from the dead - even after deleting the job in the Sidekiq Web UI it still manages to re-run. This has been going on for over two months now, and after deleting the job, when I boot up the Rails app it will send.
The job is part of an Invitation System, wherein the inviter gets an email notification when someone accepts the invite. I've never had 37 Member records so it's unclear how it's looking for ID 37, and it's unclear how the job keeps on running. Any idea?
Console Log
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
Upvotes: 2
Views: 464
Reputation: 164629
If that is indeed config/initializers/sidekiq.rb
then your Sidekiq is configured for testing.
Specifically require 'sidekiq/testing/inline'
puts it in inline test mode which causes Sidekiq to execute jobs immediately. And the rest of your configuration is for the RSpec
testing framework.
This should be instead in an isolated test directory such as spec/support/config/
. Load it with something like this in spec/rails_helper.rb
.
Rails.root.join('spec/support/').glob('**/*.rb') { |f| require f }
See Clean RSpec configuration directory structure for Ruby on Rails gems needed in testing.
Upvotes: 3