Created
March 25, 2013 22:57
-
-
Save leocassarani/5241634 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 WorkerScheduler | |
include Celluloid | |
def initialize(users) | |
@workers = users.map do |user| | |
Worker.new(user) | |
end | |
tick | |
end | |
def tick | |
@workers.each { |worker| worker.async.work } | |
after(10) { tick } | |
end | |
end | |
class Worker | |
include Celluloid | |
attr_reader :user | |
def initialize(user) | |
@user = user | |
end | |
def work | |
json = Twitter::UserTimeline.fetch(user) # This will block | |
# Send JSON off to another actor... | |
end | |
end | |
class Application < Celluloid::SupervisionGroup | |
USERS = %w(bascule brixen headius) | |
supervise WorkerScheduler, args: USERS, as: :worker_scheduler | |
end | |
Application.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment