我正在嘗試使用Sidekiq來運行以下作業。使用Sidekiq進行活動作業並獲取ActiveJob :: DeserializationError
作業在未排隊(perform_now)時表現良好,但在調用爲(perform_later)時使用Sidekiq失敗。
AddEmployeesToRoomJob.perform_now room ## works fine
AddEmployeesToRoomJob.perform_later room ## breaks in Sidekiq
錯誤:
AddEmployeesToRoomJob JID-da24b13f405b1ece1212bbd5 INFO: fail: 0.003 sec
2016-08-20T14:57:16.645Z 19456 TID-owmym5fbk WARN: {"class":"ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper","wrapped" :"AddEmployeesToRoomJob","queue":"default","args": [{"job_class":"AddEmployeesToRoomJob","job_id":"0ba5bd30-e281-49a7-a93f- 6e50445183ac","queue_name":"default","priority":null,"arguments": [{"_aj_globalid":"gid://dragonfly/Room/1"}],"locale":"en"}],"retry":true, "jid":"da24b13f405b1ece1212bbd5","created_at":1471704675.739077,"enqueued _at":1471705036.6406531,"error_message":"Error while trying to deserialize arguments: Couldn't find Room with 'id'=1","error_class":"ActiveJob::DeserializationError","failed_at":14717 04675.946183,"retry_count":4,"retried_at":1471705036.644416}
2016-08-20T14:57:16.645Z 19456 TID-owmym5fbk WARN: ActiveJob::DeserializationError: Error while trying to deserialize arguments: Couldn't find Room with 'id'=1
2016-08-20T14:57:16.645Z 19456 TID-owmym5fbk WARN: /Users/tamlyn/.rvm/gems/ruby-2.2.3/gems/activerecord- 5.0.0.1/lib/active_record/relation/finder_methods.rb:357:in `raise_record_not_found_exception!'
我的工作 類AddEmployeesToRoomJob < ApplicationJob queue_as:默認
def perform(room)
employees = Employee.all
if employees.length > 0
employees.each do |employee|
UserRoom.create(user: employee, room: room)
end
end
end
end
我思考 我不明白爲什麼它找不到我進入執行方法的房間。就好像它在排隊/ JSON化工作中失去了那個變量?
的Sidekiq文檔說
「不幸的是,這意味着如果作業排隊後[房間]記錄被刪除,但執行方法被調用之前,異常處理是不同的。」
他們建議的方法,但我看不出這將幫助我:
rescue_from ActiveJob::DeserializationError do |exception|
# handle a deleted user record
end
在此先感謝您的幫助!
https://github.com/mperham/sidekiq/wiki/Problems-and-Troubleshooting#can not-find-modelname-with-id12345 –