Sidekiq not finding records for Rails Active Job

匆匆过客 提交于 2019-12-11 16:12:11

问题


Jobs are queued on after a user is created like so in the model

user.rb

after_create_commit :profile_photo_job

def profile_photo_job
    message = "Add a profile photo"
    ReminderJob.set(wait: 1800).perform_later(self.id.to_s, message)
end

reminder_job.rb

class ReminderJob < ApplicationJob
  queue_as :default

  def perform(user_id, message)
    if user_id
      user = User.find(user_id)
    end
    ##sending message notification here
  end

end

However, it often throws the following error inside my sidekiq console

ActiveRecord::RecordNotFound: Couldn't find User with 'id'=7749 Processor: User-MacBook-Pro.local:*****

This error happens in production.


回答1:


In User.rb

after_commit :profile_photo_job, on: :create

def profile_photo_job
    message = "Add a profile photo"
    ReminderJob.set(wait: 1800).perform_later(self.id.to_s, message)
end


来源:https://stackoverflow.com/questions/51891632/sidekiq-not-finding-records-for-rails-active-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!