コード例 #1
0
ファイル: policy.py プロジェクト: bmbouter/CeleryManagement
 def broadcast(self, name, *args, **kwargs):
     if 'reply' not in kwargs:
         kwargs['reply'] = True
     result = broadcast(name, *args, **kwargs)
     result = util._merge_broadcast_result(result)  # turn it into a single dict
     result = util._condense_broadcast_result(result)  # remove worker key
     for k,v in result.iteritems():
         if isinstance(v, dict) and 'error' in v:
             raise RuntimeError('Found error in broadcast()')
     return result
コード例 #2
0
ファイル: api.py プロジェクト: bmbouter/CeleryManagement
 def get(self):
     if len(self.names) != 1:
         msg = 'Cannot retrieve this attribute for multiple workers.'
         raise ApiError(msg)
     r = self._broadcast('stats', destination=self.names, reply=True)
     r = util._merge_broadcast_result(r)
     if not r:
         raise ApiError('Unable to retrieve worker attribute: prefetch.')
     r = util._condense_broadcast_result(r)
     if isinstance(r, dict) and 'error' in r:
         raise ApiError('Error occurred while retrieving worker prefetch.')
     return r['consumer']['prefetch_count']
コード例 #3
0
ファイル: manager.py プロジェクト: bmbouter/CeleryManagement
def get_all_task_settings():
    """ Like get_task_settings(), but it always returns the settings for all 
        tasks in all workers. 
    """
    # don't do anything if there are no workers
    if len(util.get_all_worker_names()) == 0:
        return {}
    settings = util.broadcast('get_task_settings', 
                         arguments={'tasknames': None, 
                         'setting_names': _setting_names}, 
                         reply=True)
    settings = util._merge_broadcast_result(settings)
    return util._condense_broadcast_result(settings) or {}
コード例 #4
0
ファイル: api.py プロジェクト: bmbouter/CeleryManagement
 def get(self):
     if len(self.names) != 1:
         msg = 'Cannot retrieve this attribute for multiple workers.'
         raise ApiError(msg)
     r = self._broadcast('stats', destination=self.names, reply=True)
     r = util._merge_broadcast_result(r)
     if not r:
         msg = 'Unable to retrieve worker attribute: subprocess pool.'
         raise ApiError(msg)
     r = util._condense_broadcast_result(r)
     if isinstance(r, dict) and 'error' in r:
         msg = 'Error occurred while retrieving worker subprocess pool.'
         raise ApiError(msg)
     return len(r['pool']['processes'])
コード例 #5
0
ファイル: api.py プロジェクト: bmbouter/CeleryManagement
 def __set__(self, taskapi, value):
     value = self.validator(value)
     arguments = {'tasknames': taskapi.names, 'attrname':self.attrname, 
                  'value': value}
     r = taskapi._broadcast('set_task_attribute', arguments=arguments, 
                            reply=True)
     r = util._merge_broadcast_result(r)
     if not r:
         msg = 'Unable to set task attribute: {0}.'.format(self.attrname)
         raise ApiError(msg)
     # check that all 'values' are equal
     r = util._condense_broadcast_result(r)
     # check that the value doesn't indicate an error
     if isinstance(r, dict) and 'error' in r:
         tmpl = 'Error occurred while setting task attribute: {0}.'
         msg = tmpl.format(self.attrname)
         raise ApiError(msg)
     taskapi._on_task_modified(self.attrname, value)
コード例 #6
0
ファイル: api.py プロジェクト: bmbouter/CeleryManagement
 def __get__(self, taskapi, owner):
     assert taskapi is not None
     if len(taskapi.names) != 1:
         raise ApiError('Cannot retrieve this attribute for multiple tasks.')
     arguments = {'taskname': taskapi.names[0], 'attrname': self.attrname}
     r = taskapi._broadcast('get_task_attribute', arguments=arguments, 
                            reply=True)
     r = util._merge_broadcast_result(r)
     if not r:
         tmpl = 'Unable to retrieve task attribute: {0}.'
         msg = tmpl.format(self.attrname)
         raise ApiError(msg)
     # check that all 'values' are equal
     r = util._condense_broadcast_result(r)
     # check that the value doesn't indicate an error
     if isinstance(r, dict) and 'error' in r:
         tmpl = 'Error occurred while retrieving task attribute: {0}.'
         msg = tmpl.format(self.attrname)
         raise ApiError(msg)
     return r