docbrown/app/workers/users/follow_worker.rb

17 lines
468 B
Ruby

module Users
class FollowWorker
include Sidekiq::Job
sidekiq_options queue: :high_priority, retry: 10, lock: :until_executed
def perform(user_id, followable_id, followable_type)
return unless %w[Tag Organization User].include?(followable_type)
user = User.find_by(id: user_id)
followable = followable_type.constantize.find_by(id: followable_id)
return unless user && followable
user.follow(followable)
end
end
end