Example #1
0
def restore_task_settings(restore_data):
    """ Restores task settings to the given values.  This restores the initial 
        task settings when the Task Manager is closed. 
        
        The restore_data argument must be a dict.  The keys correspond to task 
        names, and the values are tuples containing: 1. a dict mapping setting 
        names to their new values, and 2. a list of setting names to erase.  
        Every setting name should be found in one or the other, but not both.
        Here is a brief example (for brevity, not all setting names are shown)::
            
            {
                'task.task1': (
                    {
                        'ignore_result': True,
                    },
                    ['expires', acks_late],
                ),
                'task.task2': (
                    {
                        'exchange': 'MyExchange',
                        'routing_key': 'MyRoutingKey',
                    },
                    ['expires', 'rate_limit'],
                ),
            }
    """
    # only broadcast if there are workers
    if len(util.get_all_worker_names()):
        util.broadcast('restore_task_settings', 
                  arguments={'restore_data': restore_data})
Example #2
0
 def _broadcast(self, *args, **kwargs):
     ##print 'self._connection = {0}'.format(self._connection)
     kwargs['connection'] = self._connection
     if 'destination' in kwargs and isinstance(kwargs['destination'], list):
         kwargs['limit'] = len(kwargs['destination'])
     else:
         kwargs['limit'] = self._get_worker_count()
     return util.broadcast(*args, **kwargs)
Example #3
0
def update_tasks_settings(workername, tasks_settings):
    """ Update settings for one or more tasks in the given worker or all 
        workers. 
        
        The tasks_settings argument must be a dict with the following format: 
        dict[taskname][settingname] = settingvalue.  For example::
        
            {
                'tasks.task1': {
                    'ignore_result': False,
                    'routing_key': 'MyRoutingKey',
                },
                'tasks.task2': {
                    'acks_late': True,
                },
            }
    """
    util.broadcast('update_tasks_settings', destination=[workername],
              arguments={'tasks_settings': tasks_settings})
Example #4
0
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 {}
Example #5
0
def get_task_settings(workername, tasknames):
    """ Get the settings for one or more tasks. 
    
        :param workername: The name of a worker to get the task settings from, 
                           or None to examine all task settings.
        :param tasknames: The name or names of tasks to get settings from.  It 
                          can either be a single string, a or a tuple or list 
                          of strings.
        :returns: A dict whose format varies depending on whether a workername 
                  is supplied or not. If the workername is None, the dict has 
                  three levels: name of the worker, name of the task, name of 
                  the setting, and finally the setting's value. If a workername 
                  is supplied, the top level of the dict is omitted.
    """
    destination = [workername] if workername else None
    settings = util.broadcast('get_task_settings', destination=destination, 
                         arguments={'tasknames': tasknames, 
                         'setting_names': _setting_names}, reply=True)
    settings = util._merge_broadcast_result(settings)
    if workername:
        return settings.get(workername)
    else:
        return settings