-
-
Notifications
You must be signed in to change notification settings - Fork 271
Supervision Groups
Supervision groups provide a declarative way to supervise many actors at once. You can start or stop a group of actors in one fell swoop, and ensure that if any of them crash they'll be restarted automatically. Groups can also supervise other groups, allowing you to build supervision trees for all the components in your system, even the supervisors themselves!
To define a group, subclass Celluloid::SupervisionGroup:
class MyGroup < Celluloid::SupervisionGroup
supervise MyActor, as: :my_actor
supervise AnotherActor, as: :another_actor, args: [{start_working_right_now: true}]
pool MyWorker, as: :my_worker_pool, size: 5
endThis group, when started, will launch MyActor and AnotherActor and automatically register them as Celluloid::Actor[:my_actor] and Celluloid::Actor[:another_actor]. It will also start a pool of 5 MyWorkers and register them as Celluloid::Actor[:my_worker_pool]. See Pools for more information about working with actor pools.
Use :args to pass arguments to the actor's initialize method, its value should always be an array.
The example above will result in calling something like AnotherActor.new(start_working_right_now: true).
To launch your group, do:
MyGroup.runThis launches your group in the foreground. To launch it in the background, do:
MyGroup.run!class Person
include Celluloid
def initialize(age, height, weight)
p(age: age, height: height, weight: weight)
end
def bar
rand(20)
end
end
supervisor = Celluloid::SupervisionGroup.run!
supervisor.pool(Person, as: :people, args: [1,2,3], size: 3)
p Celluloid::Actor.all.size
10.times do
# DISCLAIMER: This is new functionality only available on master as of March 8th 2014.
# Use: p Celluloid::Actor[:people].bar for version 0.15.2
p supervisor[:people].bar
endSee Also:
- Supervisors: supervise individual actors
- Registry: name actors
- Celluloid::SupervisionGroup: YARD documentation
Always feel free to:
- Visit the
#celluloidchannel on freenode. - Post a bug report or feature request.
- Ask questions on our mailing list.