Created
April 9, 2012 09:24
-
-
Save Amokrane/2342485 to your computer and use it in GitHub Desktop.
Using Iron.IO for pushing notifications
This file contains 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
require 'iron_worker' | |
class NotifsPusher | |
def perform | |
begin | |
puts "Initializing IronWorker and pushing billions of C2dm into it..." | |
IronWorker.configure do |config| | |
config.token = ENV['IRON_WORKER_TOKEN'] | |
config.project_id = ENV['IRON_WORKER_PROJECT_ID'] | |
end | |
c2dms = C2dm.all.first(1000) | |
c2dms_for_worker = [] | |
c2dms.each_with_index do |c2dm, i| | |
if i > 0 && i % 50 == 0 | |
puts "IronWorker::Queueing worker for #{i}" | |
worker = C2dmIronWorker.new | |
worker.c2dms = c2dms_for_worker | |
worker.params = {'message' => 'test' } | |
worker.queue | |
c2dms_for_worker = [] | |
end | |
c2dms_for_worker << c2dm | |
end | |
rescue => e | |
STDERR.puts "IronWorker::Error synchronizing users data #{e}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment