Skip to content

Instantly share code, notes, and snippets.

@samnang
Created March 10, 2014 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samnang/9468764 to your computer and use it in GitHub Desktop.
Save samnang/9468764 to your computer and use it in GitHub Desktop.
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