コード例 #1
0
ファイル: restart.py プロジェクト: max0d41/circus
def execute_watcher_start_stop_restart(arbiter, props, watcher_function_name,
                                       watchers_function, arbiter_function):
    """base function to handle start/stop/restart watcher requests.
    since this is always the same procedure except some function names this
    function handles all watcher start/stop commands
    """
    if 'name' in props:
        name = re.compile(fnmatch.translate(props['name']))
        watchers = [watcher
                    for watcher in arbiter.iter_watchers()
                    if name.match(watcher.name.lower())]
        if not watchers:
            raise MessageError("program %s not found" % props['name'])

        if len(watchers) == 1:
            if props.get('waiting'):
                resp = TransformableFuture()
                func = getattr(watchers[0], watcher_function_name)
                resp.set_upstream_future(func())
                resp.set_transform_function(lambda x: {"info": x})
                return resp
            return getattr(watchers[0], watcher_function_name)()

        watcher_iter_func = lambda reverse=True: \
            sorted(watchers, key=lambda a: a.priority, reverse=reverse)
        return watchers_function(watcher_iter_func=watcher_iter_func)
    else:
        return arbiter_function()
コード例 #2
0
ファイル: reload.py プロジェクト: BrainBot/circus
 def execute(self, arbiter, props):
     graceful = props.get('graceful', True)
     sequential = props.get('sequential', False)
     if 'name' in props:
         watcher = self._get_watcher(arbiter, props['name'])
         if props.get('waiting'):
             resp = TransformableFuture()
             resp.set_upstream_future(watcher.reload(
                 graceful=graceful,
                 sequential=sequential))
             resp.set_transform_function(lambda x: {"info": x})
             return resp
         return watcher.reload(graceful=graceful,
                               sequential=sequential)
     else:
         return arbiter.reload(graceful=graceful, sequential=sequential)
コード例 #3
0
ファイル: restart.py プロジェクト: iccodegr/circus
def execute_watcher_start_stop_restart(arbiter, props, watcher_function_name,
                                       watchers_function, arbiter_function):
    """base function to handle start/stop/restart watcher requests.
    since this is always the same procedure except some function names this
    function handles all watcher start/stop commands
    """
    if 'name' in props:
        name = re.compile(fnmatch.translate(props['name']))
        watchers = [watcher
                    for watcher in arbiter.iter_watchers()
                    if name.match(watcher.name.lower())]
        if not watchers:
            raise MessageError("program %s not found" % props['name'])

        if len(watchers) == 1:
            if props.get('waiting'):
                resp = TransformableFuture()
                func = getattr(watchers[0], watcher_function_name)
                resp.set_upstream_future(func())
                resp.set_transform_function(lambda x: {"info": x})
                return resp
            return getattr(watchers[0], watcher_function_name)()

        def watcher_iter_func(reverse=True):
            return sorted(watchers, key=lambda a: a.priority, reverse=reverse)

        return watchers_function(watcher_iter_func=watcher_iter_func)
    else:
        return arbiter_function()
コード例 #4
0
ファイル: decrproc.py プロジェクト: iccodegr/circus
 def execute(self, arbiter, props):
     watcher = self._get_watcher(arbiter, props.get('name'))
     nb = props.get('nb', 1)
     resp = TransformableFuture()
     resp.set_upstream_future(watcher.decr(nb))
     resp.set_transform_function(lambda x: {"numprocesses": x})
     return resp
コード例 #5
0
ファイル: incrproc.py プロジェクト: yegorich/circus
 def execute(self, arbiter, props):
     watcher = self._get_watcher(arbiter, props.get('name'))
     if watcher.singleton:
         return {"numprocesses": watcher.numprocesses, "singleton": True}
     else:
         nb = props.get("nb", 1)
         resp = TransformableFuture()
         resp.set_upstream_future(watcher.incr(nb))
         resp.set_transform_function(lambda x: {"numprocesses": x})
         return resp
コード例 #6
0
 def execute(self, arbiter, props):
     if 'name' in props:
         watcher = self._get_watcher(arbiter, props['name'])
         if props.get('waiting'):
             resp = TransformableFuture()
             resp.set_upstream_future(watcher.start())
             resp.set_transform_function(lambda x: {"info": x})
             return resp
         return watcher.start()
     else:
         return arbiter.start_watchers()
コード例 #7
0
 def execute(self, arbiter, props):
     graceful = props.get('graceful', True)
     sequential = props.get('sequential', False)
     if 'name' in props:
         watcher = self._get_watcher(arbiter, props['name'])
         if props.get('waiting'):
             resp = TransformableFuture()
             resp.set_upstream_future(
                 watcher.reload(graceful=graceful, sequential=sequential))
             resp.set_transform_function(lambda x: {"info": x})
             return resp
         return watcher.reload(graceful=graceful, sequential=sequential)
     else:
         return arbiter.reload(graceful=graceful, sequential=sequential)