Skip to content

Commit

Permalink
adds another example
Browse files Browse the repository at this point in the history
  • Loading branch information
ask committed Dec 2, 2011
1 parent a64c64e commit c49136d
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/clex.py
@@ -0,0 +1,57 @@
import cl

from celery import current_app as celery


class BlenderActor(cl.Actor):
default_routing_key = "default"

def __init__(self, connection=None, *args, **kwargs):
# - use celery's connection by default,
# - means the agent must be started from where it has access
# - to the celery config.
super(BlenderActor, self).__init__(
connection or celery.broker_connection(), *args, **kwargs)

class state:
# - The state class defines the messages the actor can handle,
# - so a message with method 'render' will be dispatched to
# - the render method.

def render(self, blabla):
print("communicates with the blender process here")
return "value"


# - It is good practice to provide helper methods, so that
# - clients don't have to use .call, etc directly

def render(self, blabla, nowait=False):
return self.call_or_cast("render", {"blabla": blabla}, nowait=nowait)
blender = BlenderActor()


class Agent(cl.Agent):
actors = [blender]

def __init__(self, connection=None, *args, **kwargs):
# - use celery's connection by default
super(Agent, self).__init__(
connection or celery.broker_connection(), *args, **kwargs)


if __name__ == "__main__":
Agent().run_from_commandline()


####
# Run this script in one console, and in another run the following:
#
# >>> from x import blender
#
# >>> # call and wait for result
# >>> blender.render("foo").get()
# 'value'
#
# >>> # send and don't care about result
# >>> blender.render("foo", nowait=True)

0 comments on commit c49136d

Please sign in to comment.