Skip to content


Subversion checkout URL

You can clone with
Download ZIP


petergoldstein edited this page · 18 revisions

You may be familiar with tools like Monit or God which keep an eye on your applications and restart them when they crash. Celluloid supervisors work in a similar fashion, except instead of monitoring applications, they monitor individual actors and restart them when they crash. Crashes occur whenever an unhandled exception is raised anywhere within an actor.

To supervise an actor, start it with the supervise method. Using the Sheen class from the basic usage example:

>> supervisor = Sheen.supervise "Charlie Sheen"
 => #<Celluloid::Supervisor(Sheen) "Charlie Sheen">

This created a new Celluloid::Supervisor actor, and also created a new Sheen actor, giving its initialize method the argument "Charlie Sheen". The supervise method has the same method signature as new. However, rather than returning the newly created actor, supervise returns the supervisor. To retrieve the actor that the supervisor is currently using, use the Celluloid::Supervisor#actors method:

>> supervisor = Sheen.supervise "Charlie Sheen"
 => #<Celluloid::Supervisor(Sheen) "Charlie Sheen">
>> charlie = supervisor.actors.first
 => #<Celluloid::Actor(Sheen:0x00000100a312d0)>

Supervisors can also automatically put actors into the actor registry using the supervise_as method:

>> Sheen.supervise_as :charlie, "Charlie Sheen"
 => #<Celluloid::Supervisor(Sheen) "Charlie Sheen">
>> charlie = Celluloid::Actor[:charlie]
 => #<Celluloid::Actor(Sheen:0x00000100a312d0)>

In this case, the supervisor will ensure that an actor of the Sheen class, created using the given arguments, is always available by calling Celluloid::Actor[:charlie]. The first argument to supervise_as is the name you'd like the newly created actor to be registered under. The remaining arguments are passed to initialize just like you called new.

See Also:

Something went wrong with that request. Please try again.