Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{"name": name, "min": min, "max": max}, to=name, **kw)
def consuming_from(self, name, **kw):
return self.send_to_able("consuming_from",
{"name": name}, to=name, **kw)
def stats(self, name, **kw):
return self.send_to_able("stats", {"name": name}, to=name, **kw)
@property
def meta(self):
return {"nodes": self.state.all()}
nodes = Node()
class Queue(ModelActor):
"""Actor for managing the Queue model."""
model = models.Queue
exchange = Exchange("xscs.Queue")
types = ("direct", "scatter", "round-robin")
default_timeout = 2
meta_lookup_section = "queues"
class state:
def all(self):
return [q.name for q in self.objects.all()]
def get(self, name):
try:
return self.objects.get(name=name).as_dict()
except self.model.DoesNotExist:
def contribute_to_state(self, state):
state.model = self.model
state.objects = self.model._default_manager
return Actor.contribute_to_state(self, state)
@cached_property
def name(self):
return unicode(self.model._meta.verbose_name.capitalize())
@cached_property
def name_plural(self):
return unicode(self.model._meta.verbose_name_plural).capitalize()
class App(ModelActor):
"""Actor for managing the app model."""
model = models.App
types = ("scatter", )
exchange = Exchange("xscs.App")
_cache = {}
class state:
def all(self):
return [app.name for app in self.objects.all()]
def add(self, name, broker=None):
return self.objects.add(name, broker=broker).as_dict()
def delete(self, name):
return self.objects.filter(name=name).delete() and "ok"
else:
self._cache[name] = objects.instance(**app)
return self._cache[name]
def _get(self, name):
try:
return self.state.get(name)
except self.Next:
replies = self.scatter("get", {"name": name}, propagate=False)
for reply in replies:
if not isinstance(reply, Exception):
return reply
apps = App()
class Node(ModelActor):
"""Actor for managing the Node model."""
model = models.Node
exchange = Exchange("xscs.Node")
default_timeout = 60
types = ("direct", "scatter", "round-robin")
meta_lookup_section = "nodes"
class state:
def all(self, app=None):
fun = self.objects.all
if app:
fun = partial(self.objects.filter, app=apps.get(app))
return [node.name for node in fun()]
def get(self, name, app=None):