Created
March 10, 2014 16:45
-
-
Save samnang/9468764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NotificationsWorker | |
include Sidekiq::Worker | |
sidekiq_options queue: :notification, retry: false | |
def perform(actor_id, user_ids, action, target_type, target_id) | |
actor = User.find(actor_id) | |
target = target_type.constantize.find(target_id) | |
notifications = [] | |
ActiveRecord::Base.transaction do | |
user_ids.each do |user_id| | |
notification = Notification.create( | |
user_id: user_id, | |
action: action, | |
actor: actor, | |
target: target | |
) | |
notifications.push(PushNotification.new(notification).notification) | |
end | |
end | |
Urbanairship.batch_push(notifications) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment