Skip to content

Instantly share code, notes, and snippets.

@leocassarani
Created March 25, 2013 22:57
Show Gist options
  • Save leocassarani/5241634 to your computer and use it in GitHub Desktop.
Save leocassarani/5241634 to your computer and use it in GitHub Desktop.
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